Search Unity

How to Use SendBytesToPlayer?

Discussion in 'Multiplayer' started by Deleted User, Jul 22, 2017.

  1. Deleted User

    Deleted User

    Guest

  2. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    it looks like that is a way to basically send raw bytes to a player. like outside of the usual command/rpc/syncvar/message system.

    i think the only way you can leverage that is by using your own derived version of NetworkConnection, and overriding its TransportReceive method
     
    Deleted User likes this.
  3. Deleted User

    Deleted User

    Guest


    https://docs.unity3d.com/ScriptReference/Networking.NetworkConnection.html

     
  4. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    more specifically, look at this example for what i'm talking about - - https://docs.unity3d.com/ScriptReference/Networking.NetworkConnection.TransportReceive.html

    you could read the byte array directly here or pass it to the base handler. the base handler calls HandleBytes which in turn calls HandleReader, which basically just looks for a network message, extracts it, and passes it on to a message handler.

    I could see this SendBytesToPlayer technique coming in handy if you're treating an entire channel this way. like say for example, you're passing a raw microphone data to a player. you could devote a whole channel for that and just send the raw bytes. it could save you a little bit of overhead i suppose since you don't need to pack it into a message.

    otherwise, i think it's a little messy to handle messages and raw bytes from a single channel. there's a pretty high likelihood of misinterpreting a valid message as a raw byte array and completely missing the message.

    there are other clever uses for this i suppose....like if you were sending really short messages (like < 4 bytes). basically that doesn't really conform to the network message structure, so it would be really easy to filter them out in TransportReceive
     
    Deleted User likes this.