De/Serialize problems in transmit between client/server
Options
Hello,all.
I encounter some de/serialize problems in transmitting datas between server and client,
please help me.
1.Can't I de/serialize Guid?
I do
PhotonPeer.RegisterType(typeof(Guid), (byte)'G', SerializeGuid, DeserializeGuid);
in client side, and
Photon.SocketServer.Protocol.TryRegisterCustomType(typeof(Guid), (byte)'G', SerializeGuid, DeserializeGuid);
in server side.
But it still some problem,
client can serialize Guid using "SerializeGuid" function and server will deserialize Guid using "DeserializeGuid" function , it ok,
but server won't using "SerializeGuid" function to serialize Guid, and sure, client won't deserialize it using "DeserializeGuid" function, client will recv a byte[16] data.
I think, is there a build-in guid serializer in server , but not in client?
How can I De/Serialize Guid like build-in types?
2.How can I use registered CustomType de/serializer in client and server?
In client, can I use Protocol.Serialize(somedata) and Protocol.Deserialize(somedata) to serialize and deserialize customType data?
And What can I use in Server?
3.Why I can't serialize Dictionary<Guid,Hashtable> or List<Guid> or List<Hashtable> or something like that?
How can I do to serialize it?
Thank you for reading my post,and hope I can find some answers here.
Thanks !
I encounter some de/serialize problems in transmitting datas between server and client,
please help me.
1.Can't I de/serialize Guid?
I do
PhotonPeer.RegisterType(typeof(Guid), (byte)'G', SerializeGuid, DeserializeGuid);
in client side, and
Photon.SocketServer.Protocol.TryRegisterCustomType(typeof(Guid), (byte)'G', SerializeGuid, DeserializeGuid);
in server side.
But it still some problem,
client can serialize Guid using "SerializeGuid" function and server will deserialize Guid using "DeserializeGuid" function , it ok,
but server won't using "SerializeGuid" function to serialize Guid, and sure, client won't deserialize it using "DeserializeGuid" function, client will recv a byte[16] data.
I think, is there a build-in guid serializer in server , but not in client?
How can I De/Serialize Guid like build-in types?
2.How can I use registered CustomType de/serializer in client and server?
In client, can I use Protocol.Serialize(somedata) and Protocol.Deserialize(somedata) to serialize and deserialize customType data?
And What can I use in Server?
3.Why I can't serialize Dictionary<Guid,Hashtable> or List<Guid> or List<Hashtable> or something like that?
How can I do to serialize it?
Thank you for reading my post,and hope I can find some answers here.
Thanks !
0
Comments
-
This is a known issue and we got a fix. It's just not yet released.
I guess you host Photon yourself?
The problem is: Guids are sent as pure byte[] by the clients. Those are cast to Guids on demand, if the server expects them somewhere.
You will be able to de/serialize Guids as custom types with that fix. Then you should also be able to use them as keys in dictionaries.
I asked colleagues for the details. Maybe they can provide a date for an update.0 -
There's still problems,
2.How can I use registered CustomType de/serializer in client and server?
In client, can I use Protocol.Serialize(somedata) and Protocol.Deserialize(somedata) to serialize and deserialize customType data?
And What can I use in Server?
if i need to serial List<T> in my own serializer , how can I do?
if i need to Deserial List<T> in my own Deserializer , how can I do?0 -
Please check out my post in this thread for an example of server-side custom type serialization: viewtopic.php?f=8&t=3028#p13947
Let me know if this helps or if you have further questions.0 -
Thank you for your reply,
There is another problem with de/serialize,
I want to serialize a class like this
public class Message
{
int type;
object[] m_data1;
Hashtable m_data2;
}
and I have register the de/serializer
Photon.SocketServer.Protocol.TryRegisterCustomType(typeof(Message), (byte)'M', SerializeMessage, DeserializeMessage);
private static byte[] SerializeMessage(object customobject)
{
Message Msg = (Message)customobject;
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
formatter.Serialize(ms, Msg);
return ms.GetBuffer();
}
private static object DeserializeMessage(byte[] bytes)
{
MemoryStream ms = new MemoryStream(bytes);
BinaryFormatter formatter = new BinaryFormatter();
Message Msg = new Message();
Msg = (Message)formatter.Deserialize(ms);
return Msg;
}
but it will failed, when m_Data1 or m_Data2 have any thing is not [Serializable],
like unityEngine.Vector3.
How can I serialize it?0 -
Hi.
You will have to register each class that you want to be able to put into m_data1 or m_data2 as a custom type and just check that they don't hold anything for which you have not registered its class as a custom type.0 -
Hi,
Hashtable with unityEngine.Vector3 in it is OK to transmit between server / client, because photon support it.
But I have a CutomType, that Customtype has a Hashtable with Vector3 in it , then I don't know how to serialize it! Because I can't use the serializer that photon support for hashtable.
How can I do for that?
By the way Vector3 is already registed.0