- Home /
Sending binary data causes unexpected problems on server.
Hi,
I am currently developing a Unity based game for mobile platforms which communicates with a Java Applet running on AppEngine to save the game state. I am currently in the process of switching from formatting an object's fields into form fields and then transmitting this form to the server with the goal of persisting my data to directly parsing my objects as binary data using protobuf-net and sending this to the server instead. The thing is that I still want to use form fields to add additional info (such as session cookies) that would get directly serialized as binary data. Therefore, I tried to take my already existing form and adding the serialized object using WWWForm.AddBinaryData The problem is that as soon as I use this method, my server-side login doesn't work anymore. Basically, it seems like it wrecks the data transmission process/disturbs the form integrity somehow. Here's a code sample showing how I send the data:
public IEnumerator AddNewBuilding(OnNetResult callback, GeneralBuildingScript newBuilding)
{
if( Game.Instance.GetUser() == "" || !Game.Instance.SessionCookieIsSet )
callback(ReturnCode.Error, "Not connected !");
// Login info, I still want this as form fields
WWWForm form = new WWWForm();
form.AddField("nm", Game.Instance.GetUser() );
form.AddField("cookie", Game.Instance.GetSessionCookie() );
form.AddField("action","testAdd");
form.AddField("manager","Buildings");
// Old parameters, are now contained in the serialized object
form.AddField("posX",newBuilding.Coordinates[0].ToString());
form.AddField("posY",newBuilding.Coordinates[2].ToString());
form.AddField("angle",newBuilding.RotationAngle.ToString());
// Serialization of an object using protobuf-net
using (MemoryStream memStream = new MemoryStream())
{
Serializer.Serialize<GeneralBuildingScript>(memStream, newBuilding);
byte[] dataBuffer = memStream.GetBuffer();
form.AddBinaryData("binaryData", dataBuffer ) ;
WWW www = new WWW(Game.ServerUrl, form);
yield return www;
tryConnection("Error", www, callback);
}
Now, if I am not mistaken, combining binary data and normal form fields isn't supposed to cause any problems ( like in this example ). Is there something I am missing ? do I have to switch to the other, "form-less" version of WWW and send the straight binary data ? Did anyone else experiment with protobuf or protobuf-net and Unity ? Any help is welcome.
same problem here. my servlet request parameters become empty when there's mixing AddField and AddBinaryData on the Unity client. any updates on this?
Answer by pfialho · Apr 16, 2013 at 10:28 AM
it is probably because your server doesn't support multipart requests. see http://stackoverflow.com/questions/3337056/convenient-way-to-parse-incoming-multipart-form-data-parameters-in-a-servlet
Your answer
Follow this Question
Related Questions
EndOfStreamException: Failed to read past end of stream. 0 Answers
Best way to serialize a ScriptableObject reference using NetworkWriter/Reader 1 Answer
How to serialize an object to a byte array 1 Answer
Photon (PUN) Type Serialization Error on RPC 2 Answers
WWWForm speed different between Android and iOS device 1 Answer