Win a copy of Java Challengers this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Socket stream get stuck?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I'm trying to create a scenario with clinet server talking to each other in stream, here is the code:



when the client is only writing and server just reading it's ok, but when I added the ability of server to write back
(output stream) it gets stuck on the marked line in Server.java

any ideas how to fix this?

Thanks,
Gal
 
Bartender
Posts: 9625
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I read your code correctly, the situation is thus: You write data from the client to the server. The server reads until EOF. Your client never sends EOF (done by closing the client side input stream).
BTW: using available() is not a good idea. It only indicates how much data is available for reading without blocking. It's a better idea to read some large block of data. If less data is available, read will do the right thing. See here
 
Gal Rubinstein
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but when I close the OutputStream by calling stream.close(); I get a "socket is close" exception on 'socket.getInputStream();'

is there another way of closing the output stream without closing the socket?

Thanks,
Gal
 
Joe Ess
Bartender
Posts: 9625
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spend some time with the Sockets Chapter of the Java Tutorial. I think seeing sockets in use will help you out.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic