• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 9626
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: 9626
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic