/// <summary> /// Stops the server. /// </summary> public void Stop() { if (!IsOpen) { throw new NetworkException("Attempted to close an already closed socket."); } ThrowSafe.Execute(() => Socket.Shutdown(SocketShutdown.Both)); ThrowSafe.Execute(() => Socket.Close()); }
/// <summary> /// Disconnects the client. /// </summary> /// <param name="reason">The reason for the disconnection.</param> public void Disconnect(string reason) { lock (Drivers.Locks.NetworkLock) { if (Disconnected) { return; } Disconnected = true; DisconnectReason = reason; ThrowSafe.Execute(() => Socket.Shutdown(SocketShutdown.Both)); ThrowSafe.Execute(() => Socket.Disconnect(false)); if (ShouldHandleDisconnect && OnDisconnect != null && Data != null) { OnDisconnect.Invoke(Data); } } }