This week's book giveaway is in the Features new in Java 9 forum.
We're giving away four copies of Java 9 Revealed and have Kishori Sharan on-line!
See this thread for details.
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

for socket,How to manually make inputstream.read () return -1  RSS feed

 
Alger Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for socket,How to manually make inputstream.read () return -1,thanks
 
Knute Snortum
Sheriff
Posts: 3603
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you expand on your question or create a SSCCE (that's a link)?
 
Alger Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Could you expand on your question or create a SSCCE (that's a link)?


 
Knute Snortum
Sheriff
Posts: 3603
86
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember to UseCodeTags (that's a link) when you post code.  I'll do it for you this time.
 
Dave Tolls
Ranch Hand
Posts: 2551
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you're talking about purely on the client?
Then include a flag that is read checked in the while clause at the same time as reading from the socket.
 
Norm Radder
Rancher
Posts: 1772
26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking how to keep the read() method from blocking in the fun() method?
 
Alger Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:So you're talking about purely on the client?
Then include a flag that is read checked in the while clause at the same time as reading from the socket.

yes.in client,when large number of data(uncertain length) is sent completely, how to make server's inputstream.read() exit block

or
in server ,for some reason ,I want to make inputstream.read() exit block as fun1() above in another thread
 
Alger Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Are you asking how to keep the read() method from blocking in the fun() method?


yes
 
Norm Radder
Rancher
Posts: 1772
26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can rewrite the code, Look at the java.nio.channels classes for non-blocking methods.

You should probably redesign the code if blocking in the fun() method is a problem.  Would closing the socket cause the stream to return -1?
 
Alger Smith
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:If you can rewrite the code, Look at the java.nio.channels classes for non-blocking methods.

You should probably redesign the code if blocking in the fun() method is a problem.  Would closing the socket cause the stream to return -1?


not closing the socket, it needs to communitate  yet later
 
Norm Radder
Rancher
Posts: 1772
26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not closing the socket, it needs to communitate  yet later

Then try the java.nio.channels classes
Or redesign the fun() method to run in another thread so it does not block the thread that you are having problems with.
 
Campbell Ritchie
Sheriff
Posts: 54012
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Removed from Beginning forum as too difficult a question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!