- Home /
Unexpected Data Received - Photon Server, XmlSerializer and Unity
Hello,
I am working on a game in Unity using the Photon Server. I have been following along with CJR Gaming's excellent tutorials and have now been adding onto their framework to suit my own game. My problem occurs with the serialization of an object, a deck of cards to be more specific. See, when I start the game, the player can create a deck of cards and edit the deck of cards by adding and removing cards from it. When the player has finished editing his deck he then presses a "Save" button that sends a request to my Photon server to save the deck into the database. The way I send the deck is serialize it and put it in the parameters of the request. Here is the code I am using to serialize my deck:
XmlSerializer serializer = new XmlSerializer(typeof(List<CardListItem>));
StringWriter writer = new StringWriter();
serializer.Serialize(writer, this.DeckList);
Dictionary<byte, object> parameters = new Dictionary<byte, object>()
{
{(byte)ClientParameterCode.SubOperationCode, MessageSubCode.SaveDeck},
{(byte)ClientParameterCode.DeckId, deckId},
{(byte)ClientParameterCode.DeckList, writer.ToString()}
};
OperationRequest request = new OperationRequest { OperationCode = (byte)ClientOperationCode.Login, Parameters = parameters };
If the deck saves successfully, it saves into my database as a (very long) string since it turns all of the objects in the deck into strings beforehand. I did some stress tests with how many cards I could serialize, and, when I serialize 30 of the same card, it serializes and saves correctly. However, when I serialize 31 of the same card, the server gives me an "Unexpected data received" at the PeerBase. I have a feeling that I should be serializing the information a different way than a string but I don't know a good way to go about it. I assume that there is some kind of throttle on either the serializer or message limit or elsewhere. I researched some XmlSerializer limits and it seems unlikely that the serializer is being overloaded. I changed the message limit on my server config to double the size and that didn't help either. I am kind of stuck with this and I don't really know a better way go about fixing it since the error message is quite vague.
Thanks in advance!
Turns out there is a max length of strings beings sent to the server. It's around 32kb.
Your answer
Follow this Question
Related Questions
Photon Server 1 Answer
Client-Server implementation suggestions for asynchronous multiplayer mobile game? 1 Answer
Remote database for leaderboard 2 Answers
Best way to connect to database for my mobile game? 3 Answers
[Closed] www.data help 0 Answers