Esempio n. 1
0
        /**
         * count+timestamp+dataLen+data
         *
         * @param count
         * @return
         */
        public IByteBuffer rttMsg(int count)
        {
            IByteBuffer buf = Unpooled.DirectBuffer(10);

            buf.WriteShort(count);
            buf.WriteInt((int)(KcpUntils.currentMs() - startTime));

            //int dataLen = new Random().nextInt(200);
            //buf.writeBytes(new byte[dataLen]);

            int dataLen = data.ReadableBytes;

            buf.WriteShort(dataLen);
            buf.WriteBytes(data, data.ReaderIndex, dataLen);
            return(buf);
        }
Esempio n. 2
0
        public KcpRttExampleClient()
        {
            data = Unpooled.DirectBuffer(200);
            for (int i = 0; i < data.Capacity; i++)
            {
                data.WriteByte((byte)i);
            }

            rtts = new int[300];
            for (int i = 0; i < rtts.Length; i++)
            {
                rtts[i] = -1;
            }

            timer20.Enabled  = true;
            timer20.Interval = 20;
            timer20.Start();
            startTime = KcpUntils.currentMs();
        }
Esempio n. 3
0
        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]);
            }
        }