How to reuse socket in .NET?

后端 未结 4 857
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 03:28

I am trying to reconnect to a socket that I have disconnected from but it won\'t allow it for some reason even though I called the Disconnect method with the argument \"reus

4条回答
  •  生来不讨喜
    2020-12-14 04:01

    After reading the MSDN documentation for Socket.Disconnect I noticed something that might be causing your issue.

    If you need to call Disconnect without first calling Shutdown, you can set the SocketOption named DontLinger to false and specify a nonzero time-out interval to ensure that data queued for outgoing transmission is sent. Disconnect then blocks until the data is sent or until the specified time-out expires. If you set DontLinger to false and specify a zero time-out interval, Close releases the connection and automatically discards outgoing queued data.

    Try setting the DontLinger Socket option and specify a 0 timeout or use Shutdown before you call disconnect.

提交回复
热议问题