示例#1
0
        public void Close()
        {
            UdpClient client = this._udpClient;

            lock (this._receivedDatas)
            {
                if (this._udpClient == null)
                {
                    return;
                }
                this._udpClient = null;
                this._receivedDatas.Clear();
            }

            this._state = State.Disconnect;

            if (this._kcpProxy != null)
            {
                this._kcpProxy.Dispose();
                this._kcpProxy = null;
            }
            this._pingScheduler.Stop();

            client.Close();
            client.Dispose();
            this._rpcManager.Clear();
        }
示例#2
0
        private void ProcessReceiveDatas()
        {
            this._receivedDatas.Switch();
            while (!this._receivedDatas.isEmpty)
            {
                ReceivedData receivedData = this._receivedDatas.Pop();
                byte[]       data         = receivedData.data;
                int          offset       = 0;
                int          size         = data.Length;

                if (!this.VerifyConnKey(data, ref offset, ref size))
                {
                    continue;
                }

                switch (this._state)
                {
                case State.Connecting:
                    if (!this.VerifyHandshakeAck(data, ref offset, ref size))
                    {
                        continue;
                    }

                    ushort peerId = 0;
                    if (!this.VerifyPeerId(data, ref offset, ref size, ref peerId))
                    {
                        continue;
                    }
                    this.id        = peerId;
                    this._kcpProxy = new KCPProxy(this.id, this.OnKCPOutput, (log, user) => /*Logger.Net( $"KCP log:{log}" )*/ { });
                    this._state    = State.Connected;
                    this._pingScheduler.Start(NetworkConfig.PING_INTERVAL, this.SendPing);
                    this._activeTime = TimeUtils.utcTime;
                    this.OnSocketEvent?.Invoke(new SocketEvent(SocketEvent.Type.Connect, string.Empty, SocketError.Success, null));
                    break;

                case State.Connected:
                    this._activeTime = TimeUtils.utcTime;
                    this._kcpProxy.ProcessData(data, offset, size, this.OnKCPRecv);
                    break;
                }
            }
        }
示例#3
0
 internal KCPUserToken(ushort id)
 {
     this.id        = id;
     this._kcpProxy = new KCPProxy(this.id, this.OnKCPOutout, (log, user) => /* Logger.Net( $"KCP log:{log}" )*/ { });
 }