public TChannel(TcpClient tcpClient, IPEndPoint ipEndPoint, TService service) : base(service) { this.tcpClient = tcpClient; this.parser = new PacketParser(this.recvBuffer); this.RemoteAddress = ipEndPoint; //发起连接 //if (ctype == ChannelType.Connect) //{ // this.ConnectAsync(ipEndPoint); //} ////接受连接 //else if (ctype == ChannelType.Accept) //{ // this.OnConnected(); //} }
/// <summary> /// 创建channel,分为客户端请求和服务端接受两种情况 /// </summary> /// <param name="service"></param> /// <param name="id"></param> /// <param name="remoteEndPoint"></param> /// <param name="socket"></param> public KChannel(ChannelType ctype, KService service, uint id, IPEndPoint remoteEndPoint, UdpClient socket) : base(service) { this.Id = id; //this.RemoteId = remoteid; this.remoteEndPoint = remoteEndPoint; this.socket = socket; this.parser = new PacketParser(this.recvBuffer); this.lastRecvTime = service.TimeNow; this.channelType = ctype; if (ctype == ChannelType.Connect) { this.Connect(service.TimeNow); } else if (ctype == ChannelType.Accept) { kcp = new Kcp(this.Id, this.OnKcpSend); kcp.SetMtu(512); kcp.NoDelay(1, 10, 2, 1); //fast this.isConnected = true; } }