Socket code – answer

Did you spot the bug? The server writes to the socket using:

 out.write("From server: " + nextResponse);

The client reads using:

while ((fromServer = in.readLine()) != null) {

However, the PrintWriter write method doesn’t put a carriage return at the end of the data. Hence, no matter how much data the server sends, the client will never receive any of it.

This entry was posted in Java and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

503,088 Spambots Blocked by Simple Comments

HTML tags are not allowed.