public void OnReceiveData(byte[] data, IPEndPoint ipEndpoint) { Debug.Log($"Recibiendo: " + data); PacketHeader header = new PacketHeader(); MemoryStream stream = new MemoryStream(data); header.Deserialize(stream); if (header.packetType == (ushort)PacketType.User) { UserTypeHeader userHeader = new UserTypeHeader(); userHeader.Deserialize(stream); InvokeCallback(header.objectId, userHeader.packetType, stream, null); } else { InvokeCallback(header.objectId, header.packetType, stream, ipEndpoint); } stream.Close(); }
private byte[] Serialize(ISerializablePacket packet, uint objectId) { PacketHeader header = new PacketHeader(); MemoryStream stream = new MemoryStream(); header.id = currentPacketId; header.senderId = ConnectionManager.Instance.clientId; header.objectId = objectId; header.packetType = (ushort)packet.packetType; header.Serialize(stream); if (packet.packetType == (ushort)PacketType.User) { UserTypeHeader userHeader = new UserTypeHeader(); userHeader.packetType = (ushort)packet.UserType; userHeader.Serialize(stream); } packet.Serialize(stream); stream.Close(); return(stream.ToArray()); }