This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start here: Don't println to a Socket. readline() has the same problem.
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Ulf Dittmer.
 
It's just a flesh wound! Or a tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!