❔ Socket.Connected for listening sockets?

The Socket class contains a Connected property, but not Listening. I'm trying to check for a break in connectivity when a socket is listening. EG: if a client connects to a server then Connected is true, and will become false when the client disconnects. I'm not finding an equivalent for when the server is listening, or if the socket is somehow dropped.
2 Replies
Anchy
Anchy2y ago
I would just implement a kind of heartbeat packet, so the server will send the client this small packet to just test the connection. The client can expect this packet as well and send back a response to this heartbeat that way both sides will know if there has been a disconnect because if there is one you won't be able to write to the host/client stream as it will be closed You could also create a packet for disconnecting that you can send to the server/client to notify them that you are disconnecting and then handle that. the Socket.Connected properly may also not be reliable since it only saves the socket state of the last I/O operation as remarked in the msdocs
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server