public void Disconnect(Exception ex) { if (NetworkSocket != null) { NetworkSocket.Shutdown(SocketShutdown.Both); NetworkSocket.Dispose(); NetworkSocket = null; OnDisconnect?.Invoke(this, ex); } }