Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

when does a read method return -1 in a socket  RSS feed

 
vijay kolli
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I opened a datainputstream on a client socket. and the server is sending data periodically.

I am reading the data using this call: datainputstream.read(byte[])... so when would this return -1? I know that read method would return -1 when reading from a file and it is the end of the file.
 
Rob Spoor
Sheriff
Posts: 20937
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the socket connection is closed. That's the only time you can guarantee that no more data will come.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!