Search Unity

Sending data through Unity Relay Service using C++ networking plugin

Discussion in 'Multiplayer' started by kromenak, Mar 5, 2019.

  1. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    Hi everyone, I'm currently using Unity Matchmaking and Unity Relay Service to match up two clients and send an initial game state between the two. This works well under pretty much any network scenario.

    The game I'm working on uses peer-to-peer "lockstep" networking implemented in a C++ plugin. As a result, after matchmaking and initial game state is shared, I need to tell the C++ plugin what connection info to use ( IP address and port) for the peer.

    I have implemented fairly basic NAT punch-through to enable this P2P connection to work under many network conditions. I've noticed that in some cases, NAT punch-through fails, so it would be ideal to have this C++ plugin utilize the relay transport already created for the initial game state sharing using Unity Relay Service as a fallback.

    Is there any documentation, reference, or examples for how I can send a UDP packet in C++ that can be successfully routed through the Unity Relay Service to my opponent as a "fall back" in case NAT punch-through fails? Clearly both clients can easily send UDP data through the relay service in C#, so I don't see any reason I can't also do it in C++, assuming I can determine the relay service endpoint and any extra data the relay service needs in the packet for routing.

    I'm aware that Unity has deprecated UNET functionality, but I am developing a prototype/proof of concept, so this is not meant to be used in production in any way! We want to prove out the tech with pre-existing services before we commit to building our own backend servers for this.