protected void ShutdownSocket() { // Only do this once if (!IsListening) return; IsListening = false; // Stop accepting connections try { Listener.Shutdown(SocketShutdown.Both); } catch { } // Close the listener Listener.Close(); }