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

Discussion in 'Java' started by jeremywilms, Jun 17, 2008.

  1. jeremywilms

    jeremywilms

    Joined:
    Jun 17, 2008
    Messages:
    1
    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.
    jeremywilms, Jun 17, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kosio

    Floats to chars and chars to floats

    Kosio, Sep 16, 2005, in forum: C Programming
    Replies:
    44
    Views:
    1,282
    Tim Rentsch
    Sep 23, 2005
  2. Hongyu
    Replies:
    9
    Views:
    897
    James Kanze
    Aug 8, 2008
  3. Mark

    convert integer to array of chars

    Mark, Feb 23, 2010, in forum: C Programming
    Replies:
    6
    Views:
    1,207
  4. M.Posseth

    receiving ??? chars instead of "special" chars

    M.Posseth, Nov 15, 2004, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    224
    Dan Rogers
    Nov 16, 2004
  5. Eric
    Replies:
    3
    Views:
    90
    Jay Tilton
    May 8, 2004
Loading...

Share This Page