コード例 #1
0
        public static Packet Read(Stream stream)
        {
            // Read header
            BinaryReader  reader  = new BinaryReader(stream);
            PacketOptions options = (PacketOptions)reader.ReadByte();
            int           length  = reader.ReadInt32();

            byte[] bytes  = reader.ReadBytes(length);
            var    packet = new Packet(bytes, options);

            if (packet.IsCompressed)
            {
                packet._bytes = bytes.Decompress();
            }
            if (packet.HasChecksum)
            {
                int checksumLength = reader.ReadInt16();
                packet._checksum = reader.ReadBytes(checksumLength);
                if (!packet.HasValidChecksum())
                {
                    throw new InvalidDataException("Bad checksum reading packet");
                }
            }
            return(packet);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AndroidRemote"/> class.
 /// </summary>
 /// <param name="socket">The socket.</param>
 public AndroidRemote(TcpClient socket)
 {
     NetworkStream = socket.GetStream();
     PacketWriter  = new PacketWriter(this);
     PacketReader  = new PacketReader(this);
     PacketOptions = new PacketOptions()
     {
         UseBigEndian         = true,
         UseShortAsHeaderSize = true
     };
 }
コード例 #3
0
        public static Packet Create(byte[] bytes, PacketOptions options = PacketOptions.Checksum)
        {
            var packet = new Packet(bytes, options);

            if (packet.IsEncrypted)
            {
                throw new NotImplementedException("Packet encryption not supported");
            }
            if (packet.HasChecksum)
            {
                packet._checksum = Hasher.ComputeHash(packet._bytes);
            }
            return(packet);
        }
コード例 #4
0
ファイル: PacketingFormatter.cs プロジェクト: avgx/OrigoDB
 public PacketingFormatter(IFormatter decoratedFormatter, PacketOptions options)
 {
     Ensure.NotNull(decoratedFormatter, "decoratedFormatter");
     _decoratedFormatter = decoratedFormatter;
     _options = options;
 }
コード例 #5
0
ファイル: NetworkTag.cs プロジェクト: rsptim1/FlareNet
 public NetworkTagAttribute(ushort tag, PacketOptions options = PacketOptions.Reliable)
 {
     Value         = tag;
     packetOptions = (PacketFlags)options;
 }
コード例 #6
0
 public static extern TPacketID wirefox_peer_send(IntPtr handle, IntPtr packet, TPeerID recipient, PacketOptions options, PacketPriority priority, TChannelIndex channelIndex);
コード例 #7
0
ファイル: Peer.cs プロジェクト: iridinite/wirefox
 public uint Send(Packet packet, PeerID recipient, PacketOptions options, PacketPriority priority = PacketPriority.MEDIUM)
 {
     return(NativeMethods.wirefox_peer_send(m_handle, packet.GetHandle(), recipient, options, priority, 0));
 }
コード例 #8
0
 public PacketingFormatter(IFormatter decoratedFormatter, PacketOptions options)
 {
     Ensure.NotNull(decoratedFormatter, "decoratedFormatter");
     _decoratedFormatter = decoratedFormatter;
     _options            = options;
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PacketReader"/> class.
 /// </summary>
 /// <param name="c">The remote.</param>
 public PacketReader(IRemote c)
 {
     mReader     = new BinaryReader(c.NetworkStream);
     this.remote = c;
     options     = c.PacketOptions;
 }
コード例 #10
0
 private Packet(byte[] bytes, PacketOptions options = PacketOptions.Checksum)
 {
     _options = options;
     _bytes   = bytes;
 }