Example #1
0
        public void HandleConnnect(uint remoteConn)
        {
            if (this.isConnected)
            {
                return;
            }

            this.RemoteConn = remoteConn;

            this.kcp = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn));
            Kcp.KcpSetoutput(
                this.kcp,
                (bytes, len, k, user) =>
            {
                KService.Output(bytes, len, user);
                return(len);
            }
                );
            Kcp.KcpNodelay(this.kcp, 1, 10, 1, 1);
            Kcp.KcpWndsize(this.kcp, 256, 256);
            Kcp.KcpSetmtu(this.kcp, 470);

            this.isConnected  = true;
            this.lastRecvTime = this.GetService().TimeNow;

            HandleSend();
        }
Example #2
0
        // accept
        public KChannel(uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept)
        {
            this.InstanceId = IdGenerater.GenerateId();

            this.LocalConn      = localConn;
            this.RemoteConn     = remoteConn;
            this.remoteEndPoint = remoteEndPoint;
            this.socket         = socket;
            this.kcp            = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn));
            Kcp.KcpSetoutput(
                this.kcp,
                (bytes, len, k, user) =>
            {
                KService.Output(bytes, len, user);
                return(len);
            }
                );
            Kcp.KcpNodelay(this.kcp, 1, 10, 1, 1);
            Kcp.KcpWndsize(this.kcp, 256, 256);
            Kcp.KcpSetmtu(this.kcp, 470);
            this.isConnected           = true;
            this.isRecvFirstKcpMessage = false;
            this.lastRecvTime          = kService.TimeNow;
            this.CreateTime            = kService.TimeNow;
        }
Example #3
0
        // accept
        public KChannel(uint localConn, uint remoteConn, Socket socket, IPEndPoint remoteEndPoint, KService kService) : base(kService, ChannelType.Accept)
        {
            this.InstanceId   = IdGenerater.GenerateId();
            this.memoryStream = this.GetService().MemoryStreamManager.GetStream("message", ushort.MaxValue);

            this.LocalConn      = localConn;
            this.RemoteConn     = remoteConn;
            this.remoteEndPoint = remoteEndPoint;
            this.socket         = socket;
            this.kcp            = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn));
            Kcp.KcpSetoutput(
                this.kcp,
                (bytes, len, k, user) =>
            {
                KService.Output(bytes, len, user);
                return(len);
            }
                );
            Kcp.KcpNodelay(this.kcp, 1, 10, 1, 1);
            Kcp.KcpWndsize(this.kcp, 256, 256);
            Kcp.KcpSetmtu(this.kcp, 470);
            this.lastRecvTime = kService.TimeNow;
            this.createTime   = kService.TimeNow;
            this.Accept();
        }
Example #4
0
 public static int KcpOutput(IntPtr bytes, int len, IntPtr kcp, IntPtr user)
 {
     KService.Output(bytes, len, user);
     return(len);
 }