示例#1
0
        public TChannel(long id, IPEndPoint ipEndPoint, TService service)
        {
            this.ChannelType        = ChannelType.Connect;
            this.Id                 = id;
            this.Service            = service;
            this.socket             = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            this.socket.NoDelay     = true;
            this.parser             = new PacketParser(this.recvBuffer, this.Service);
            this.innArgs.Completed += this.OnComplete;
            this.outArgs.Completed += this.OnComplete;

            this.RemoteAddress = ipEndPoint;
            this.isConnected   = false;
            this.isSending     = false;

            this.Service.ThreadSynchronizationContext.PostNext(this.ConnectAsync);
        }
示例#2
0
        public TChannel(long id, Socket socket, TService service)
        {
            this.ChannelType        = ChannelType.Accept;
            this.Id                 = id;
            this.Service            = service;
            this.socket             = socket;
            this.socket.NoDelay     = true;
            this.parser             = new PacketParser(this.recvBuffer, this.Service);
            this.innArgs.Completed += this.OnComplete;
            this.outArgs.Completed += this.OnComplete;

            this.RemoteAddress = (IPEndPoint)socket.RemoteEndPoint;
            this.isConnected   = true;
            this.isSending     = false;

            // 下一帧再开始读写
            this.Service.ThreadSynchronizationContext.PostNext(() =>
            {
                this.StartRecv();
                this.StartSend();
            });
        }