Sending binary data causes unexpected problems on server.


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() );		

        // Old parameters, are now contained in the serialized object

        // 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.

it is probably because your server doesn’t support multipart requests. see java - Convenient way to parse incoming multipart/form-data parameters in a Servlet - Stack Overflow