• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with echo server and client.

 
Reiner Herman
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HAllo.

I am staring and staring at my code below but can not work out what i have don wrong.
A client connects successfully to the server and gets the message "Echoserver running" from the server but when writing to the server nothing happens. A hint to make me locate the logical flaw would be nice!

Client:



Server:

 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Change the == on line 50 of EchoClient to !=

2) Don't println to a socket. Instead of using println(), use print, explicitly print out the line separator you want, and manually flush:


After these changes your echo server and client are working just fine with me.
 
Reiner Herman
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply.
The changes does not make it work for me. I changed to use print and adding "\r\n" and flushing instead of println when to socket streams.
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you also change the == into != ?
 
Reiner Herman
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. But of course I should also remember to move the System.out.println inside the while loop when changing == to !=. And now it works )
Thank you very much for the help. Should have asked a few days ago ! Especially the problem with println was tricky I think. I am nos sure that I understand why the == does not work. I will think a little more about it.
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
readLine() will return null when you've already read all there is to read. So the loop was executing exactly zero times, because the condition was false from the start.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic