예제 #1
0
        protected override void BeforeSendOutgoing(byte[] data)
        {
            //这里的data已经不是用户数据,已经包含了reliable
            var type = (Utilities.PackType)data[0];

            switch (type)
            {
            case PackType.Udp:
                var sendbuf = new byte[PackSettings.HEADER_LEN + data.Length];
                defpb.Write(sendbuf, data, 0, data.Length);
                OutgoingData.Enqueue(sendbuf);
                break;

            case PackType.Kcp:
                if (this.Context.EncoderData == null)
                {
                    return;
                }

                //交给kcp需要去掉第一个字节,不是直接发
                fixed(byte *b = &data[1])
                {
                    ikcp_send(this.Context.EncoderData, b, data.Length - 1);
                }

                break;

            default:
                throw new UnknownTypeException("unknown packtype");
                break;
            }
        }
예제 #2
0
        protected virtual int udp_output(byte *buf, int len, k.IKCPCB *kcp, void *user)
        {
            byte[] kcppack = new byte[len];
            Marshal.Copy(new IntPtr(buf), kcppack, 0, len);
#if PRINTPACK
            Console.WriteLine($"kcp_output:size{kcppack.Length}:{string.Join(",", kcppack)}");
#endif
            var sendbuf = new byte[PackSettings.HEADER_LEN + kcppack.Length];
            defpb.Write(sendbuf, kcppack, 0, kcppack.Length);
            OutgoingData.Enqueue(sendbuf);
            return(0);
        }
예제 #3
0
        protected override unsafe int udp_output(byte *buf, int len, k.IKCPCB *kcp, void *user)
        {
            //一定是reliable
            byte[] kcppack = new byte[len + 1];
            Marshal.Copy(new IntPtr(buf), kcppack, 1, len);
            kcppack[0] = (byte)PackType.Kcp;
#if PRINTPACK
            Console.WriteLine($"kcp_output:size{kcppack.Length}:{string.Join(",", kcppack)}");
#endif
            var sendbuf = new byte[PackSettings.HEADER_LEN + kcppack.Length];
            defpb.Write(sendbuf, kcppack, 0, kcppack.Length);
            OutgoingData.Enqueue(sendbuf);
            return(0);
        }