Sending bulk data via rpc

I'd like to send large chunks of bytes via RPC to my clients. This could be as much as 256k at a time. It's not constant, just at certain times.

It doesn't look like RPC has the ability to just send a byte[] array of values, so I've looked at converting bytes into a string.

Is there a better way to send this information to the clients, from my server? A key qualifier of "better" to me is ease of use. The RPC feature in Unity looks very easy to use, so I don't mind the string->byte->string conversion if it means avoiding a much more complicated way of sending the data.

I had that problem too. I've also used the serializing approach. If there's a better way that would be nice. In OnSerializeNetworkView you can send a custom mix of data but it would be nice to do that with RPCs. At least a byte array as parameter would be nice. I guess as string each letter is still serialized as a 16bit character, so that wouldn't be nice to reduce the packet size. For one-shot transfers i think serialize to string is the easiest way at the moment.

1 Answer

1

This is an old question, but it is absolutely possible to send byte arrays with RPC - it’s just not a documented feature. I am currently using it to transmit images between networked Unity instances (after encoding to jpg or png), and it has worked fine for 10k up to 300k transfers, though note that RPC seems to buffer the calls, meaning that if you’re sending data faster than the pipe can handle or the receiving function can process you’ll get farther and farther behind as time goes on - you may want to include a timestamp header on your data transfers and throw away RPC calls when they get too stale.

Undocumented - so, would you mind documenting how you did it here?

Yes, a small example would be very helpful :)

This answer is a life saver! When will Photon reference this or write their own?

I know this question is already answered and quite old but I just want to add that Unity "lately" added JPG [encoding][1] to Unity so there is no longer a need for an external library. cheers. [1]: http://docs.unity3d.com/ScriptReference/Texture2D.EncodeToJPG.html

Responding to Mexallon: Yeah, excellent point! However a note of caution: Unity doesn't allow you to specify a 'quality' for the resulting jpg. So if you want control over the amount of compression / lossiness, you're still better off using an external library. Why they didn't just use one of the existing implementations that allows you to specify quality, I don't know.