question

Tom avatar image
Tom asked

HTTP PUT request to custom game server.

Our game records some of the gameplay, which I then want to upload to our Playfab CDN as an accessible replay for other users. I am hosting a custom game server via the Multiplayer Legacy Servers service as an intermediary to verify the replay data and authorise it being sent on to the CDN.

The server is a Unity Server build which listens for upload request via an HttpListener, the client, when appropriate, attempts to send the replay data (~100kb) via a UnityWebRequest.Put.

The flow works fine, the CDN can receive the files and other clients can download and replay them. However, only when I am running the server on my local windows machine. When I package a build and upload it to the Legacy Servers service, whilst the flow works correctly, the binary data is incorrect.

For debug purposes, I am writing out two files. One at the last moment before sending the UnityWebRequest and one immediately after receiving the file on the server. These two files do not match. Whilst they are largely the same and contain the same number of bytes, a diff of the two files shows a number of discrepancies scattered throughout.

An example of the client send:

var www = UnityWebRequest.Put(url, data); // where data is byte[]
www.SetRequestHeader("Content-Type", "application/octet-stream");
File.WriteAllBytes(path, www.uploadHandler.data);
 
var asyncOperation = www.SendWebRequest();

// etc

An example of the server receive:

var listener = (HttpListener)result.AsyncState;
var context = listener.EndGetContext(result);
var request = context.Request;
var response = context.Response;

var stream = new MemoryStream();
request.InputStream.CopyTo(stream);

File.WriteAllBytes(path, stream.ToArray());

Is there something about the environment hosting the Legacy Servers that I need to be taking into account for my data to work correctly?

Custom Game Servers
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sarah Zhang avatar image Sarah Zhang commented ·

We are investigating it. We will inform you if there is any progress.

0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

As far as we know, legacy servers don’t cause such a discrepancy. You can try running your code on an AWS VM to see if a similar issue still occurs.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Tom avatar image Tom commented ·

The original byte[] array was written by a BinaryWriter that was incorrectly not specifying an encoding type. Adding the encoding type and reading from the request stream on the server with another BinaryWriter instead of copying the array resolved the issue.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.