• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket stream get stuck?  RSS feed

 
Gal Rubinstein
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!