2

When two end points (A & B) are connected via socket , and end point A disconnects, does end point B necceserily gets notified about the disconnection?

What will be the trigger for end point B to know that the connection was lost?

Will he get notified about the disconnection when he sends data to end point A?

Please focus the answer to the properties of the TCP protocol, ignoring specific language implementation.

Guy Segal
  • 953
  • 1
  • 12
  • 24

2 Answers2

0

It depends what you mean by 'disconnects'. If you mean that A closes the socket properly, B gets an end-of-stream when it reads (recv() returns zero.) If you mean that it aborts, various things can happen depending on the platforms concerned, but most likely B will get an ECONNRESET after a couple of send() calls.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

When a client(A) abruptly disconnects or crashes while the server(B) is sending chunks of information though write() , the server will possibly receive an EPIPE or SIGPIPE signal. This signal is usually preceded by a RESET signal.

RESET is the way for TCP to tell the sender that the receiver is unwilling to accept further data. But since the sender has already transmitted blocks of data, it would see the EPIPE or SIGPIPE signals before it knows about the RESET signal.

Here's the link to help you understand better.

vasanth89
  • 36
  • 4
  • Another [similar question](http://stackoverflow.com/questions/2974021/what-does-econnreset-mean-in-the-context-of-an-af-local-socket) which explains things in detail. – vasanth89 Apr 03 '14 at 08:09
  • So which is it? RESET precedes or follows? You've stated both here. – user207421 Apr 03 '14 at 08:50
  • `RESET` precedes the `EPIPE` signal. The server might see the `EPIPE` signal because it is in the middle of sending data and might not know that the client is not willing to accept data(which it had informed earlier with `RESET' signal) – vasanth89 Apr 11 '14 at 19:42