Socket problem - readline won't work properly

后端 未结 5 1279
灰色年华
灰色年华 2020-12-11 13:09

I try to code a client and server connection using socket. The problem is my client can\'t read the response from the server (it hangs on the readline).

Here is some

5条回答
  •  无人及你
    2020-12-11 13:18

    According to the javaDoc, the server response actually is

    "My Message:\n"+System.getProperty("line.separator")
    

    I bet, in.readLine() works fine at least once - but you just ignore the response, because the print command is outside the loop. Move that one up, and you should see the responses on the console.

    There is a (very small) chance, that the servers println() doesn't really send a \n char. So you could try this at the thread code:

     out.print(clientResponse+"\n\n");  // exchanged println with an extra \n char
    

提交回复
热议问题