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
How to Use a Delimiter with Scanner.Usedelimiter in Java
"Integer Number Too Large" Error Message for 600851475143
Inject an Ejb into Jax-Rs (Restful Service)
Java Cannot Make a Static Reference to Non-Static Field
Java.Lang.Unsatisfiedlinkerror No *****.Dll in Java.Library.Path
Get Width and Height of JPAnel Outside of the Class
Convert Float to Double Without Losing Precision
Runnable Jars Missing Images/Files (Resources)
How to Convert Currenttimemillis to a Date in Java
Remove All Occurrences of Char from String
Why Does the Jtable Header Not Appear in the Image
Converting Symbols, Accent Letters to English Alphabet
Simple Popup Java Form with at Least Two Fields
Java Thread.Sleep Puts Swing UI to Sleep Too
What Is an Object's Hash Code If Hashcode() Is Not Overridden