简体   繁体   中英

Can the client read the remainin data in a socket after connection is lost for some reason?

Scenario: client connect to a server using TCP and then the server sends 3 messages.

The server successfully sends 3 messages to the client. Meanwhile, the client machine receives the messages but the client didn't read any of them using dataInputStream.read /...

Then, while the client starts reading the first message he received, the server closes the connection or the connection is lost for any other reason.

My question - Does the client will be able to read the data he didn't yet read but is available to him? or all the remaining data in the socket is unavailable for the client anymore?

These are two different scenarios.

Then, while the client starts reading the first message he received, the server closes the connection

No data is lost. The client will read all the data that was sent and then receive an end of stream.

or the connection is lost for any other reason.

All pending data is discarded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM