Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using InputStream.available() when recieving data from server

Status
Not open for further replies.

borbjo

Programmer
Mar 29, 2002
33
0
0
NO

I use InputStream.available() when recieving data from server to see if the server responded.

If it is 0, I do not do anything (assume the response was negative)..

But does it wait for the server, or could it give me 0 in a case where the server has not yet responded?
 
in TCP connection any client/server operations are coordinated by both, clients and servers

Ion Filipski
1c.bmp
 
Hmm, it doesn't seem that way,

cause I get available()==0 about 1 of 10 times when I know the server sends the same response each time.
 
it is because in the stream is not any data. By the way, this function is very expensive in computer processor and memory resources. If you want wait until serevr sends some data is much better to use read* family functions. By the way, no data will be sent from the server until server side output stream is not flush()'ed. So, if server writes something in the stream, it does not mean what this data is sent to client. Function available checks the input stream for available data, and does not result in a call from client to server. When some data exist in the stream, the value of available will be different than 0. If there is some error on the connection, you will get an exception.

Ion Filipski
1c.bmp
 
Ok, thank you for that explanation Ion :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top