aspose file tools
The moose likes Beginning Java and the fly likes Reading from an Socket and it hands at in.readline()!=null Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Reading from an Socket and it hands at in.readline()!=null" Watch "Reading from an Socket and it hands at in.readline()!=null" New topic
Author

Reading from an Socket and it hands at in.readline()!=null

saumil baxi
Ranch Hand

Joined: Apr 18, 2008
Posts: 58
Hi,

I am writing a simple server client application,
at the server end whenever a client connects , server reads data and response back
but the server gets hang at bufferin.readline()



What is the best way to avoid if the client doesn't send an EOM. how to tell the server to stop reading from the Stream.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35237
    
    7
Start here: Don't println to a Socket. readline() has the same problem.


Android appsImageJ pluginsJava web charts
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Start here: Don't println to a Socket.

That link displayed (redirected to?) http://developer.apple.com/library/mac/navigation/index.html#topic=Technical+Notes§ion=Resource+Types. Was that your intention?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35237
    
    7
Tom Reilly wrote:That link displayed (redirected to?) http://developer.apple.com/library/mac/navigation/index.html#topic=Technical+Notes§ion=Resource+Types. Was that your intention?

Ugh, no it wasn't. Thanks for pointing that out. I can't believe they removed that article - at least it looks like they did, I can't find it on their site now. The Japanese version is still there :-)

The bottom line is: one can't reliably use "println" and "readLine" with sockets due to those methods using the default line ending that is appropriate for the platform the code runs on. Most protocols (HTTP, for example) use "\r\n" for line endings, though.

Update: I've put up an archived version of the article here.
saumil baxi
Ranch Hand

Joined: Apr 18, 2008
Posts: 58
Thanks a lot Ulf Dittmer.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Reading from an Socket and it hands at in.readline()!=null
 
Similar Threads
Socket problem
display http header
Read, Send, Write a File through a socket
What is the class to use for server in single server multiclient chat programming
Send a String to Server and server send it somewhere on network