File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Problem with echo server and client. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Problem with echo server and client." Watch "Problem with echo server and client." New topic
Author

Problem with echo server and client.

Reiner Herman
Greenhorn

Joined: Jan 12, 2010
Posts: 19
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

Joined: Oct 27, 2005
Posts: 19792
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Reiner Herman
Greenhorn

Joined: Jan 12, 2010
Posts: 19
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

Joined: Oct 27, 2005
Posts: 19792
    
  20

Did you also change the == into != ?
Reiner Herman
Greenhorn

Joined: Jan 12, 2010
Posts: 19
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

Joined: Oct 27, 2005
Posts: 19792
    
  20

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with echo server and client.