Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

What is the proper procedure for shutting down a TCPListener

$
0
0

When shutting down a TCPListener should Server (the socket) be evaluated for a connection? If a connection exists should Server Shutdown, Disconnect, and Dispose be carried out before stopping the TCPListener?

sample:

If theTCPListener IsNot Nothing Then
  Try
    If theTCPListener.Server IsNot Nothing Then
      If theTCPListener.Server.Connected Then
        theTCPListener.Server.Shutdown(System.Net.Sockets.SocketShutdown.Both)
        theTCPListener.Server.Disconnect(False)
      End If

      theTCPListener.Server.Dispose()
    End If

    p_TCPListener.Stop()
  Catch
  End Try
End If


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>