示例#1
0
        public override AChannel ConnectChannel(string host, int port)
        {
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(host), port);
            KChannel   channel    = this.CreateConnectChannel(ipEndPoint);

            return(channel);
        }
示例#2
0
        private KChannel CreateConnectChannel(IPEndPoint remoteEndPoint)
        {
            KChannel channel = new KChannel(++this.IdGenerater, this.socket, remoteEndPoint, this);

            this.idChannels[channel.Id] = channel;
            return(channel);
        }
示例#3
0
        public override Task <AChannel> AcceptChannel()
        {
            if (this.udpResults.Count > 0)
            {
                UdpReceiveResult udpReceiveResult = this.udpResults.Dequeue();
                uint             requestConn      = BitConverter.ToUInt32(udpReceiveResult.Buffer, 4);
                KChannel         kChannel         = this.CreateAcceptChannel(udpReceiveResult.RemoteEndPoint, requestConn);
                return(Task.FromResult <AChannel>(kChannel));
            }

            acceptTcs = new TaskCompletionSource <AChannel>();
            return(this.acceptTcs.Task);
        }
示例#4
0
        public override AChannel ConnectChannel(IPEndPoint remoteEndPoint)
        {
            uint     conv    = (uint)RandomHelper.RandomNumber(1000, int.MaxValue);
            KChannel channel = new KChannel(conv, this.socket, remoteEndPoint, this);
            KChannel oldChannel;

            if (this.idChannels.TryGetValue(channel.Id, out oldChannel))
            {
                this.idChannels.Remove(oldChannel.Id);
                oldChannel.Dispose();
            }
            this.idChannels[channel.Id] = channel;
            return(channel);
        }