How to check if a socket is connected/disconnected in C#?

前端 未结 11 1229
礼貌的吻别
礼貌的吻别 2020-11-28 18:50

How can you check if a network socket (System.Net.Sockets.Socket) is still connected if the other host doesn\'t send you a packet when it disconnects (e.g. because it discon

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 19:03

    Use Socket.Connected Property.

    --UPDATE--

    As Paul Turner answered Socket.Connected cannot be used in this situation. You need to poll connection every time to see if connection is still active. See 2

提交回复
热议问题