Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » TcpSocket, Know when distant connection have been closed
Re: TcpSocket receiving ghost data [message #57223 is a reply to message #57222] Sat, 12 June 2021 20:03 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1226
Registered: August 2007
Senior Contributor
Hello Xemuth,


Quote:

So here is my question, how to know when the distant socket have been closed ? I have trying many things but
either it's me who cuts the connection (probably because of a timeout or erro during WaitRead())
either I don't detect the FIN from the server side and dont react so my connection never reset


Hard to say without knowing the transactions between S/C but I suspect that remote server may have enabled SO_LINGER.
Otherwise, AFAIK, IsEof() or IsError() should return true, depending on the server.

See: https://man7.org/linux/man-pages/man7/socket.7.html

 SO_LINGER
              Sets or gets the SO_LINGER option.  The argument is a
              linger structure.

                  struct linger {
                      int l_onoff;    /* linger active */
                      int l_linger;   /* how many seconds to linger for */
                  };

              When enabled, a close(2) or shutdown(2) will not return
              until all queued messages for the socket have been
              successfully sent or the linger timeout has been reached.
              Otherwise, the call returns immediately and the closing is
              done in the background.  When the socket is closed as part
              of exit(2), it always lingers in the background.



In general, the "polite" way in networking is to let the client close its connection to the server (after it is done with transactions.). But this is more a recommendation not a strict rule.

Best regards,
Oblivion


[Updated on: Sat, 12 June 2021 20:28]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: RichEdit with word wrap?
Next Topic: Calendar
Goto Forum:
  


Current Time: Sun Aug 24 23:21:57 CEST 2025

Total time taken to generate the page: 0.04870 seconds