/// <summary> /// Stop the server and disconnect any clients /// </summary> public void Stop() { disposed = true; disconnectAll(); isRunning = false; this.listenSocket.Close(); if (OnClientConnected != null) { foreach (var receiver in OnClientConnected.GetInvocationList()) { OnClientConnected -= (RemoteClientConnectedEventHandler)receiver; } } if (OnClientDisconnected != null) { foreach (var receiver in OnClientDisconnected.GetInvocationList()) { OnClientDisconnected -= (RemoteClientDisconnectedEventHandler)receiver; } } if (OnClientMessageReceived != null) { foreach (var receiver in OnClientMessageReceived.GetInvocationList()) { OnClientMessageReceived -= (RemoteClientMessageReceivedEventHandler)receiver; } } }