TTCPBlockSocket lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- michoux · 2021-02-02 11:38 Hi, I am using TTCPBlockSocket to connect to few remote servers. **********************    connection:=TTCPBlockSocket.Create;     connection.CreateSocket;                          connection.Connect(IP,Port); ********************** All works perfect ...  ut at some point remote server can leave for some time, how can I monitor the connection so I know when to connect back? Best regards Michoux. ---------------------------------------------------------------------- sstvmaster · 2021-02-02 16:03 Hi Michoux, Quote from: michoux on February 02, 2021, 12:38:42 pm...how can I monitor the connection so I know when to connect back?... You can use ping, if its possible and the server allow ping. ---------------------------------------------------------------------- michoux · 2021-02-02 16:10 It is not that server would be gone, port on server can be closed for some time ... and then re-open. when this happens I need to manually re-connect. ---------------------------------------------------------------------- trev · 2021-02-02 23:59 Have a look at TCP keep alive. ---------------------------------------------------------------------- sstvmaster · 2021-02-03 09:14 Here are some examples: https://sourceforge.net/p/synalist/mailman/synalist- public/thread/4DDD4FEA.6060300%40ventoso.org/ https://sourceforge.net/p/synalist/mailman/synalist- public/thread/500D3EBC.30403%40sintesisrl.net/#msg29578439 ---------------------------------------------------------------------- Remy Lebeau · 2021-02-03 18:22 Quote from: michoux on February 02, 2021, 12:38:42 pmat some point remote server can leave for some time, how can I monitor the connection so I know when to connect back? You have to actively communicate with the server.  A blocking socket won't tell you the connection is gone unless you try to send or receive data after the connection is gone.  At the very least, you need to periodically attempt to read from the server, even if you don't send anything.  Eventually, a read/write operation will fail, at which time you can then close the connection and attempt to re-connect until successful.