Here is my server sockets:
And here is the code for the application requesting the data:
And second, it would help if you included a description of the problem. So far all we know is that your code compiles correctly.
Staring at code hoping to spot a bug is a pot luck exercise. Having logs that let you narrow down where your code has gone wrong helps immensely.
ETA: Actually, scratch that. I've just seen the println's.
OK, what output are you getting?
@Dave I am not getting any output which is really weird. Even my else statement in my server is not doing anything. I know it is connecting because if I close the server side it says the connection is reset. And if I remove the string passing components then it passes data perfectly fine.
Dave Tolls wrote:So where are those println calls going?
I'd sort that out first.
How are you running these?
What I just did was I went thru the code and put println("test") to see the furthest down each code printed. The results say that client side is not printing after "in = new ObjectInputStream( connectToServer.getInputStream());"
The Server side does not print after the while statement ends. Also what I find odd is that printing inside the while statement only prints once.
that is hiding an exception.
What I mean about your debugging is that there are not enough statements to track where exactly it goes wrong.
You don't print anything until you think you've read all the input in.
On the server I would expect a println before the second while and then something inside that loop (it's not as if it's a long message).
Also, which while statement only runs once?
If it's the while (accepting) (note, no '== true') then what changes the value of accepting?
On the server side it prints once inside the while((length = input.read(buffer)) != -1) loop but doesn't print again and does not print after. I believe this is where it is getting hung up.
I find it useful to run the server and client(s) in the same JVM so that the order of the debug print outs is shown.
Here is a driver I've used for testing:
Dave Tolls wrote:OK, so what does it print on the server?
What has it actually succeeded in reading, and how does that compare with what has been sent?
Here is the process and results I am testing with.
Start the server:
Sever test 1
Then I start the Client:
This prints for Client side:
Client test 1
Client test 2
Client test 3
And server side prints:
Sever test 2
Sever test 3
HLS MSG test
Sever test 4
What I have gotten from this is that by adding length = buffer.length; I am now printing the msg that I am trying to send but only if I print it inside the while loop. It does not seem to be executing any code after the while loop.
Since it only prints the stuff in the while loop once, that tells you that the read() is blocking the second time.
And the reason it blocks is because there is nothing there to read.
The client has finished sending.
However, you are now in a situation where the client is sat waiting for the server and the server is sat waiting for the client...
@Norm - I think we have her figured out man. Thanks for trying help