Ejemplo n.º 1
0
 // accept
 public KChannel(uint conn, uint remoteConn, UdpClient socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept)
 {
     this.Id             = conn;
     this.Conn           = conn;
     this.RemoteConn     = remoteConn;
     this.remoteEndPoint = remoteEndPoint;
     this.socket         = socket;
     this.parser         = new PacketParser(this.recvBuffer);
     kcp = new Kcp(this.RemoteConn, this.Output);
     kcp.SetMtu(512);
     kcp.NoDelay(1, 10, 2, 1);              //fast
     this.isConnected  = true;
     this.lastRecvTime = kService.TimeNow;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// connect
        /// </summary>
        public TChannel(TSocket socket, string host, int port, TService service) : base(service, ChannelType.Connect)
        {
            this.socket        = socket;
            this.parser        = new PacketParser(this.recvBuffer);
            this.RemoteAddress = host + ":" + port;

            bool result = this.socket.ConnectAsync(host, port);

            if (!result)
            {
                this.OnConnected(this.Id, SocketError.Success);
                return;
            }
            this.socket.OnConn += e => OnConnected(this.Id, e);
        }