Exemple #1
0
        private void KcpServer_OnClose(Ukcp ukcp)
        {
            var peer = Global.NetManager.GetPeer(ukcp);

            OnClose(peer);
            Deregister(peer);
        }
Exemple #2
0
        public NetPeer GetPeer(Ukcp ukcp)
        {
            var id = ukcp.GetUniqueId();

            channelPeers.TryGetValue(id, out var peer);
            return(peer);
        }
Exemple #3
0
 public void onConnected(Ukcp ukcp)
 {
     //OneThreadSynchronizationContext.Instance.Post((obj) =>
     //{
     //    OnConnect?.Invoke((Ukcp)obj);
     //}, ukcp);
     OnConnect?.Invoke(ukcp);
 }
Exemple #4
0
        //kcp目前不支持epoll/kqueue/IOCP,所以只在客户端上用用
        public void RegisterKcp(Ukcp ukcp)
        {
            var id   = ukcp.GetUniqueId();
            var peer = NetPeer.Create(id, ukcp);

            channelPeers[peer.ConnId] = peer;
            Log.Info(string.Format("Incoming KCP id: {0}", id));
        }
Exemple #5
0
 protected void KcpServer_OnConnect(Ukcp ukcp)
 {
     //新连接
     NetManager.Instance.RegisterKcp(ukcp);
     //ulong hostId = Global.IdManager.GetHostId(channel.RemoteAddress.ToIPv4String());
     Log.Info(string.Format("kcp_client_connected {0} {1}",
                            Basic.GenID32FromName(ukcp.user().Channel.Id.AsLongText() + ukcp.user().Channel.LocalAddress.ToIPv4String() + ukcp.user().RemoteAddress.ToIPv4String()), ukcp.user().RemoteAddress.ToIPv4String()));
 }
Exemple #6
0
 public void handleException(Exception ex, Ukcp ukcp)
 {
     //OneThreadSynchronizationContext.Instance.Post((obj) =>
     //{
     //    var objs = (object[])obj;
     //    OnException?.Invoke((Ukcp)objs[0], (Exception)objs[1]);
     //}, new object[] { ukcp, ex});
     OnException?.Invoke(ukcp, ex);
 }
Exemple #7
0
        public static NetPeer Create(uint connId, Ukcp kcpCh)
        {
            var obj = new NetPeer();

            obj.ConnId     = connId;
            obj.kcpChannel = kcpCh;
            obj.netType    = NetworkType.KCP;
            return(obj);
        }
Exemple #8
0
 protected void KcpServer_OnConnect(Ukcp ukcp)
 {
     //新连接
     NetManager.Instance.RegisterKcp(ukcp);
     //ulong hostId = Global.IdManager.GetHostId(channel.RemoteAddress.ToIPv4String());
     Log.Info(string.Format("kcp_client_connected {0} {1}",
                            ukcp.GetUniqueId(),
                            ukcp.user().RemoteAddress.ToIPv4String()));
 }
Exemple #9
0
        //kcp目前不支持epoll/kqueue/IOCP,所以只在客户端上用用
        public void RegisterKcp(Ukcp ukcp)
        {
            var cid  = ukcp.user().Channel.Id.AsLongText() + ukcp.user().Channel.LocalAddress.ToIPv4String() + ukcp.user().RemoteAddress.ToIPv4String();
            var id   = Basic.GenID32FromName(cid);
            var peer = NetPeer.Create(id, ukcp);

            channelPeers[peer.ConnId] = peer;
            Log.Info(string.Format("Incoming KCP id: {0}", id));
        }
Exemple #10
0
        public NetPeer GetPeer(Ukcp ukcp)
        {
            var cid = ukcp.user().Channel.Id.AsLongText() + ukcp.user().Channel.LocalAddress.ToIPv4String() + ukcp.user().RemoteAddress.ToIPv4String();

            var id = Basic.GenID32FromName(cid);

            channelPeers.TryGetValue(id, out var peer);
            return(peer);
        }
Exemple #11
0
 public void handleReceive(IByteBuffer byteBuf, Ukcp ukcp)
 {
     //OneThreadSynchronizationContext.Instance.Post((obj) =>
     //{
     //    var objs = (object[])obj;
     //OnReceive?.Invoke(ukcp, byteBuf);
     //   OnReceive?.Invoke((Ukcp)objs[1], (IByteBuffer)objs[0]);
     //}, new object[] { byteBuf.Retain(), ukcp });
     OnReceive?.Invoke(ukcp, byteBuf);
 }
Exemple #12
0
        public KcpHostClient(ChannelConfig channelConfig, IPEndPoint remoteAddress)
        {
            if (client == null)
            {
                client = KcpClient.Instance;
                client.init(channelConfig);
            }

            this._ukcp = client.connect(remoteAddress, channelConfig, this);
        }
Exemple #13
0
        public void handleReceive(IByteBuffer byteBuf, Ukcp ukcp)
        {
            short curCount = byteBuf.GetShort(byteBuf.ReaderIndex);

            Console.WriteLine(Thread.CurrentThread.Name + " 收到消息 " + curCount);
            ukcp.write(byteBuf);
            if (curCount == -1)
            {
                ukcp.close();
            }
        }
Exemple #14
0
        public void handleClose(Ukcp ukcp)
        {
            //OneThreadSynchronizationContext.Instance.Post((obj) =>
            //{
            //    OnClose?.Invoke((Ukcp)obj);
            //}, ukcp);

            OnClose?.Invoke(ukcp);

            Log.Info(Snmp.snmp.ToString());
            Snmp.snmp = new Snmp();
        }
Exemple #15
0
        public KcpHostClient(ChannelConfig channelConfig, IPEndPoint remoteAddress)
        {
            if (client == null)
            {
                lock (lockObj)
                {
                    if (client == null)
                    {
                        client = new KcpClient();
                        client.init(channelConfig);
                    }
                }
            }

            this._ukcp = client.connect(remoteAddress, channelConfig, this);
        }
        public void handleReceive(IByteBuffer byteBuf, Ukcp ukcp)
        {
            int curCount = byteBuf.ReadShort();

            if (curCount == -1)
            {
                timer20.Elapsed += overHandler;
            }
            else
            {
                int  idx  = curCount - 1;
                long time = byteBuf.ReadInt();
                if (rtts[idx] != -1)
                {
                    Console.WriteLine("end");
                }
                //log.info("rcv count {} {}", curCount, System.currentTimeMillis());
                rtts[idx] = (int)(KcpUntils.currentMs() - startTime - time);
                Console.WriteLine("rtt : " + curCount + "  " + rtts[idx]);
            }
        }
        public static void start()
        {
            ChannelConfig channelConfig = new ChannelConfig();

            channelConfig.initNodelay(true, 40, 2, true);
            channelConfig.Sndwnd              = 512;
            channelConfig.Rcvwnd              = 512;
            channelConfig.Mtu                 = 512;
            channelConfig.FecDataShardCount   = 3;
            channelConfig.FecParityShardCount = 1;
            channelConfig.AckNoDelay          = true;
            channelConfig.Crc32Check          = true;
            channelConfig.Conv                = 55;
            //channelConfig.setTimeoutMillis(10000);

            KcpClient kcpClient = new KcpClient();

            kcpClient.init(channelConfig);

            KcpRttExampleClient kcpClientRttExample = new KcpRttExampleClient();
            //kcpClient.connect(new InetSocketAddress("127.0.0.1",20003),channelConfig,kcpClientRttExample);

            EndPoint remoteAddress = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 20003);

            _ukcp = kcpClient.connect(remoteAddress, channelConfig, kcpClientRttExample);

            try
            {
                kcpClientRttExample.init();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #18
0
        public void DeregisterKcp(Ukcp ukcp)
        {
            var peer = GetPeer(ukcp);

            this.Deregister(peer);
        }
Exemple #19
0
 public void handleConnect(Ukcp ukcp)
 {
 }
Exemple #20
0
        private void KcpServer_OnException(Ukcp ukcp, Exception ex)
        {
            var peer = Global.NetManager.GetPeer(ukcp);

            OnException(peer, ex);
        }
Exemple #21
0
 public void handleClose(Ukcp ukcp)
 {
     Console.WriteLine(Snmp.snmp.ToString());
     Snmp.snmp = new Snmp();
 }
Exemple #22
0
 private void KcpServer_OnClose(Ukcp ukcp)
 {
     NetManager.Instance.DeregisterKcp(ukcp);
 }
Exemple #23
0
        private void KcpServer_OnReceive(Ukcp ukcp, IByteBuffer buffer)
        {
            var peer = Global.NetManager.GetPeer(ukcp);

            OnReceive(peer, buffer);
        }
Exemple #24
0
        private void KcpServer_OnReceive(Ukcp ukcp, IByteBuffer buffer)
        {
            var peer = NetManager.Instance.GetPeer(ukcp);

            OnReceiveBuffer(peer, buffer);
        }
Exemple #25
0
        private void KcpServer_OnException(Ukcp ukcp, Exception ex)
        {
            Log.Error(ex.ToString());

            NetManager.Instance.DeregisterKcp(ukcp);
        }
Exemple #26
0
 public void onConnected(Ukcp ukcp)
 {
 }
Exemple #27
0
 public static ulong GetUniqueId(this Ukcp ukcp)
 {
     return(Basic.GenID64FromName(ukcp.user().Channel.Id.AsLongText() +
                                  ukcp.user().Channel.LocalAddress.ToIPv4String() +
                                  ukcp.user().RemoteAddress.ToIPv4String() + ukcp.getConv().ToString()));
 }
 public void handleException(Exception ex, Ukcp ukcp)
 {
     Console.WriteLine(ex);
 }
Exemple #29
0
        public bool DeregisterKcp(Ukcp ukcp)
        {
            var peer = GetPeer(ukcp);

            return(this.Deregister(peer));
        }
 public void handleClose(Ukcp ukcp)
 {
 }