How to tell when a Socket has been disconnected

后端 未结 5 1317
滥情空心
滥情空心 2021-02-05 11:36

On the client side I need to know when/if my socket connection has been broken. However the Socket.Connected property always returns true, even after the server side has been d

5条回答
  •  难免孤独
    2021-02-05 11:49

    I recommend stripping out the higher-level language stuff and explore what happens at the lower-level IO.

    The lowest I've explored was while writing isectd (find on sourceforge). Using the select() system call, a descriptor for a closed socket becomes read-ready, and when isectd would attempt the recv() the socket's disconnected state can be confirmed.

    As a solution, I recommend not writing your own socket IO and use someone else's middleware. There are lots of good candidates out there. Don't forget to consider simple queuing services as well.

    PS. I would have provided URLs to all the above but my reputation (1) doesn't allow it.

提交回复
热议问题