Java Socket Why Server Can Not Reply Client

Java Socket why server can not reply client

you should add "\r\n" at the end of the String which write into stream.

example:

client :

    string = "end";
out.write(string + "\r\n");
out.flush();

server :

    out.write("to end" + "\r\n");
out.flush();
out.close();
System.out.println("end");
// break;

Java Client/Server Socket program - server not responding to client requests

The first bug is that your client waits for input from the server after connecting, but the server does not send anything. Thus your user input loop is never executed.

The second bug is that, as long as you do not enter "print stuff", the server does not respond anything to the client. So again the client waits for input from the server, instad of waiting for input from the user.

Java Socket: unable to send response to client after sending file to server

Your expectation is that read returns with no data once the server is done sending the file. This expectation is wrong. read will only return with no data if the server has closed the TCP connection and the flush you show does not close the connections but only makes sure that all buffered data are written to the TCP connection.

This means the server can still send more data after the flush and that's why your client is hanging in the read and waiting for more data.



Related Topics



Leave a reply



Submit