public static void HandlePacket(IPacket packet) { switch (packet.GetOpcode()) { case PacketCode.SensorData: break; } }
static void SendWhole(Socket sock, IPacket packet) { var stream = new MemoryStream(); var writer = new BinaryWriter(stream); byte[] payload = packet.ToBytes(); writer.Write((short)packet.GetOpcode()); writer.Write(payload.Length); writer.Write(payload); sock.Send(stream.ToArray()); }
static void SendPartial(Socket sock, IPacket packet) { var stream = new MemoryStream(); var writer = new BinaryWriter(stream); byte[] payload = packet.ToBytes(); writer.Write((short)packet.GetOpcode()); writer.Write(payload.Length); writer.Write(payload); var data = stream.ToArray(); Console.WriteLine(Utils.HexDump(data)); sock.Send(data, 0, 8, 0); Thread.Sleep(100); sock.Send(data, 8, data.Length - 8, 0); }