aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Issue with simple multi-threaded Echo server and client program 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 "Issue with simple multi-threaded Echo server and client program" Watch "Issue with simple multi-threaded Echo server and client program" New topic
Author

Issue with simple multi-threaded Echo server and client program

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Hey everyone,

I am just trying to create a simple echo server. For some reason I can't determine I will connect to the server using the client program and the server will acknowledge that it received a connection, but the server never echoes what the client sends to them.

Server:



Client:


Any help would be great.

Thanks,
Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

Well, for one thing you're using PrintWriters to send data over the network. This is a problematic practice because PrintWriter is specifically written not to throw exceptions, and you do want to know about exceptions in an environment which is likely to have them.

The other thing is that you aren't echoing the data sent exactly. You are removing line-ending characters from it. This could be a problem when your client is expecting to receive data terminated by line-ending characters.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

I didn't know that about PrintWriter. I was formatting my example off of code I saw on the Oracle tutorial page and PrintWriter was used there, next time I'll investigate more. Would PrintStream be a better option to send data across the network?

Thanks.
Hunter
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

PrintStream? Well, I looked at its API documentation and it says
Unlike other output streams, a PrintStream never throws an IOException...


But you already have an OutputStream. Why do you need anything more than that?
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Thank you that worked perfectly, still adjusting to Java vs C networking stuff.

Thanks.
Hunter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue with simple multi-threaded Echo server and client program