Converting an array of chars, to a string to an integer

Joined
Jun 17, 2008
Messages
1
Reaction score
0
I've recently programmed in C++, and am now playing around with java. What I'm trying to do is have a server communicate with a client through different ports, the servers working fine. However, the client is not. The message is sent as a string from the server, containing the following information "cp[Port issued by server]", just before it sends that to the client it creates another thread handling all messages to that port. Then the server drops the connection and the client connects to the assigned port. I think this method is called socket threading or something. Anyway if this is a bad method, don't give me a lecture on it. Okay so my problem is this.

HTML:
    public void HandleMessage(String msg)
    {
        char[] msgdc = new char[msg.length()];
        msg.getChars(0, msg.length(), msgdc,0);
        if(msgdc[0] == 'c' && msgdc[1] == 'p')
        {
             msg.getChars(2, 6, msgdc,0);
             portstr = String.valueOf(msgdc.toString()).toString();
             int q = Integer.parseInt(portstr);
             System.out.println("intV : " + q);
        }
               
    }
Ignore any unreasonable or stupid coding, as I'm just creating a prototype for now.

Okay so this is what happens, it makes its way into the if. Executes the first line. Then on the second it completely stops the execution, I check the java console, no exception. Quite strange, I tried adding a try{} catch{}, however that didn't work. Well it did, but the Exception variable didn't return any exceptions. The Excption.getCause().toString(); stopped the execution as well. By stopped executed, I mean didn't completely execute the function.

Maybe I'm doing this correctly, I'm sure you guys know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top