[fpc-pascal] How to detect connection status of a socket

Michael Schnell mschnell at lumino.de
Mon Apr 22 14:38:08 CEST 2013


On 04/22/2013 02:23 PM, Xiangrong Fang wrote:
>
> How do I tell if a socket is still connected or not?

The "connected" State of a TCP/IP socket is a rather complex issue.

A TCP IP connection is either on or off. if it gets disconnected it is 
dead and can't be reactivated but by a new open.

As long as no event happens to one of the sites, the socket is esteemed 
connected by this site. This does not mean that the other site thinks 
the same

Possible events after a successful "open" communication events are
  - data read (-> stays open)
  - write acknowledge (-> stays open)
  - write timeout (socked is forced close)
  - close request from the other site (-> socket close)
  - close request by user (-> socket close)

If there is just no communication, the socket stays open forever.

-Michael



More information about the fpc-pascal mailing list