Original Post
Hello, I was wondering if anyone could give me an idea of a good way of converting objects to a byte array for sending over sockets in C#?
// Client serializes packetBinaryFormatter bf = new BinaryFormatter();System.IO.MemoryStream ms = new System.IO.MemoryStream(1024);Packet packet = new TextPacket("Hello My World");bf.Serialize(ms, packet);byte[] bytes = ms.GetBuffer();// Send the bytes to the server...// Server deserializes packetSystem.IO.MemoryStream _memoryStream = new System.IO.MemoryStream(1024);_memoryStream.Write(receivedBytes, 0, receivedByteCount);_memoryStream.Seek(0, 0);Packet packet = (Packet)bf2.Deserialize(_memoryStream);_memoryStream.Seek(0, 0);packet.Handle();This topic has been locked by a moderator. New replies are not allowed.
GameDev.net uses cookies to ensure you have the best experience on our platform. Learn more