Beispiel #1
0
        /// <summary>
        /// 处理连接请求ACK应答
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="socket"></param>
        /// <param name="remoteEP"></param>
        private void HandleACK(Packet packet, Socket socket, EndPoint remoteEP)
        {
            var        conv = packet.RpcId;
            KcpChannel channel;

            if (this.ServiceType == NetServiceType.Client)
            {
                if (this.ClientChannel == null)
                {
                    return;
                }

                channel = this.ClientChannel as KcpChannel;
                channel.RemoteEndPoint = remoteEP as IPEndPoint;
                channel.Id             = packet.RpcId;
                channel.OnConnected    = OnConnect;
                ConnectSender.SendACK(this.ConnectParser.Packet, this.Acceptor, remoteEP, conv);
            }
            else
            {
                channel = new KcpChannel(socket, remoteEP as IPEndPoint, this, conv)
                {
                    OnConnected = OnAccept
                };
            }

            channel.InitKcp();
            channel.OnConnected?.Invoke(channel);
        }
Beispiel #2
0
        /// <summary>
        /// 处理客户端SYN连接请求
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="remoteEP"></param>
        private void HandleSYN(Socket socket, EndPoint remoteEP)
        {
            var conv = KcpConvIdCreator.CreateId();

            while (this.Channels.ContainsKey(conv))
            {
                conv = KcpConvIdCreator.CreateId();
            }
            ConnectSender.SendACK(this.ConnectParser.Packet, this.Acceptor, remoteEP, conv);
        }