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); }
/// <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 }; }
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); }
public PacketingFormatter(IFormatter decoratedFormatter, PacketOptions options) { Ensure.NotNull(decoratedFormatter, "decoratedFormatter"); _decoratedFormatter = decoratedFormatter; _options = options; }
public NetworkTagAttribute(ushort tag, PacketOptions options = PacketOptions.Reliable) { Value = tag; packetOptions = (PacketFlags)options; }
public static extern TPacketID wirefox_peer_send(IntPtr handle, IntPtr packet, TPeerID recipient, PacketOptions options, PacketPriority priority, TChannelIndex channelIndex);
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)); }
/// <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; }
private Packet(byte[] bytes, PacketOptions options = PacketOptions.Checksum) { _options = options; _bytes = bytes; }