示例#1
0
        public void SendDataPacket(DataPacket packet, bool needAck   = false,
                                   Reliability reliability           = Reliability.Reliable,
                                   CompressionLevel compressionLevel = CompressionLevel.Fastest)
        {
            packet.EncodeHeader();
            packet.EncodePayload();

            NetworkStream stream = new NetworkStream();

            stream.WriteVarInt((int)packet.Length);
            stream.WriteBytes(packet.GetBuffer());
            byte[] payload = CompressionManager.CompressionZlib(stream, compressionLevel, true);

            BatchPacket batch = new BatchPacket();

            batch.Payload  = payload;
            batch.EndPoint = ClientPeer.PeerEndPoint;

            ClientPeer.SendEncapsulatedPacket(batch, reliability, packet.Channel);
        }