Stav Alfi
Stav Alfi

Reputation: 13923

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?

Upvotes: 0

Views: 131

Answers (1)

user207421
user207421

Reputation: 310884

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.

Upvotes: 2

Related Questions