public void Stop() { Socket socket = this._socket; lock (this._receivedDatas) { if (this._socket == null) { return; } this._socket = null; this._receivedDatas.Clear(); } int count = this._tokens.Count; for (int i = 0; i < count; i++) { KCPUserToken token = this._tokens[i]; this.OnSocketEvent?.Invoke(new SocketEvent(SocketEvent.Type.Disconnect, "Server stoped", SocketError.Shutdown, token)); token.Close(); this._userTokenPool.Push(token); } this._tokens.Clear(); this._idToTokens.Clear(); socket.Shutdown(SocketShutdown.Both); socket.Close(); }
public void Update(long dt) { this._updateContext.deltaTime = dt; this._updateContext.time += dt; this.ProcessReceiveDatas(); this.CheckClientOverRange(); this.CheckClientAlive(); this.UpdateClients(); int count = this._tokens.Count; for (int i = 0; i < count; i++) { KCPUserToken token = this._tokens[i]; if (token.disconnectEvent == null) { continue; } this.OnSocketEvent?.Invoke(token.disconnectEvent.Value); token.Close(); this._tokens.RemoveAt(i); this._idToTokens.Remove(token.id); this._userTokenPool.Push(token); --i; --count; } if (this._closeEvent != null) { this.OnSocketEvent?.Invoke(this._closeEvent.Value); this._closeEvent = null; this.Stop(); } }