public virtual void Stop() { log.Debug("Stopping server! - Entering method"); try { if (this._linstener != null) { Socket socket = this._linstener; this._linstener = null; socket.Close(); log.Debug("Server is no longer listening for incoming connections!"); } } catch (Exception e) { log.Error("Stop", e); } if (this.m_clients != null) { object syncRoot; Monitor.Enter(syncRoot = this.m_clients.SyncRoot); try { TcpAsyncClient[] list = new TcpAsyncClient[this.m_clients.Keys.Count]; this.m_clients.Keys.CopyTo(list, 0); for (int i = 0; i < list.Length; i++) { var client = list[i]; client.Disconnect(); } log.Debug("Stopping server! - Cleaning up client list!"); } catch (Exception e) { log.Error("Stop", e); } finally { Monitor.Exit(syncRoot); } } log.Debug("Stopping server! - End of method!"); }
private void client_Disconnected(TcpAsyncClient client) { client.Disconnected -= this.client_Disconnected; this.RemoveClient(client); }
private void RemoveClient(TcpAsyncClient client) { object syncRoot; Monitor.Enter(syncRoot = this.m_clients.SyncRoot); try { this.m_clients.Remove(client); } finally { Monitor.Exit(syncRoot); } }
public TcpAsyncClient[] GetAllClients() { object syncRoot; Monitor.Enter(syncRoot = this.m_clients.SyncRoot); TcpAsyncClient[] result; try { TcpAsyncClient[] temp = new TcpAsyncClient[this.m_clients.Count]; this.m_clients.Keys.CopyTo(temp, 0); result = temp; } finally { Monitor.Exit(syncRoot); } return result; }