Example #1
0
        public TChannel(Socket socket, TService service) : base(service, ChannelType.Accept)
        {
            this.packetSizeCache = new byte[Packet.PacketSizeLength];
            this.memoryStream    = service.MemoryStreamManager.GetStream("message", ushort.MaxValue);

            this.socket             = socket;
            this.socket.NoDelay     = true;
            this.parser             = new PacketParser(this.recvBuffer, this.memoryStream);
            this.innArgs.Completed += this.OnComplete;
            this.outArgs.Completed += this.OnComplete;

            this.RemoteAddress    = socket.RemoteEndPoint.ToString();
            this.remoteIpEndPoint = (IPEndPoint)socket.RemoteEndPoint;
            this.isConnected      = true;
            this.isSending        = false;
        }
Example #2
0
        public TChannel(IPEndPoint ipEndPoint, TService service) : base(service, ChannelType.Connect)
        {
            this.packetSizeCache = new byte[4];
            this.memoryStream    = service.MemoryStreamManager.GetStream("message", ushort.MaxValue);

            this.socket             = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            this.socket.NoDelay     = true;
            this.parser             = new PacketParser(this.recvBuffer, this.memoryStream);
            this.innArgs.Completed += this.OnComplete;
            this.outArgs.Completed += this.OnComplete;

            this.RemoteAddress    = ipEndPoint.ToString();
            this.remoteIpEndPoint = ipEndPoint;
            this.isConnected      = false;
            this.isSending        = false;
        }
Example #3
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);
        }
Example #4
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();
            });
        }