Search Unity

[Standalone UNET Relay] MLAPI.Relay

Discussion in 'Netcode for GameObjects' started by TwoTen, Jun 13, 2018.

  1. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168

    Hello!

    I have created a UNET standalone relay that I want to share with you.

    Issues & Support
    Bugs should be reported on the GitHub Issue Tracker. Questions can be asked on this thread or in the MLAPI Discord server.

    Compatibility
    The relay is tested on the HLAPI and the MLAPI but works on all UNET projects. The Relay requires .NET Core to be installed on the target machine.

    Usage
    Using the relay is really straight forward. First, download the RelayTransport class.
    Then replace NetworkTransport with RelayTransport everywhere where these methods are used:
    • Connect
    • ConnectEndPoint
    • ConnectWithSimulator
    • AddHost
    • AddHostWithSimulator
    • AddWebsocketHost
    • Disconnect
    • Send
    • QueueMessageForSending
    • SendQueuedMessages
    • Receive
    • ReceiveFromHost
    Example: NetworkTransport.Connect(signatureGoesHere) => RelayTransport.Connect(sameSignature);


    Even if you do this, you can still use connect without relay by setting the RelayTransport.Enabled to false. Setting the RelayTransport.Enabled to false will make the relay transport act exactly like the NetworkTransport with no changes.
    And that's it!

    I really hope you find this useful. More documentation about configuration etc and the RelayTransport class can be found on GitHub. Note that the RelayTransport class is open source and is licenced as "public domain". For the exact licence. See the licence file. This licence is for the RelayTransport only and does not cover the Relay itself, any documentation or external libraries.


    GitHub
     
    Last edited: Aug 7, 2018
    markoal, LostPanda, Ladace and 3 others like this.
  2. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
  4. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
  5. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    RogDolos and Jos-Yule like this.
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    It looks like if your game currently uses Unity's relay service, that this is probably the most viable solution to keep your game running if you intend to keep it alive after Unity shuts down their relays in a few years.
     
  7. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Yea, now that it's open source it will be free with no limits. Since it's so easy to actually enable (not much code change), it should make a switch super smooth. The only thing that might be a bit offputting is the licence. It's AGPL, meaning if you change the code and use it in some way (even self host), you have to publish your source. (Ex via PR or fork)
     
    Last edited: Aug 8, 2018
  8. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Actually, after rethinking my choice of licence, I realized that AGPL was a mistake. It has been switched to GPL. This is to allow private modified versions of the software which is useful for things like custom authentication. I always want the licence to encourage creativity and collaboration, not be a limiting factor of what you can do.

    However, the RelayTransport will continue to be public domain.
     
    PiratePaprika likes this.
  9. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    Hey, this is great, thanks for doing this!
     
  10. LostPanda

    LostPanda

    Joined:
    Apr 5, 2013
    Posts:
    173
  11. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    Will this support host migration?
    That's the main reason I was away from UNet since it doesn't support host migration in relay server...
     
  12. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    I think it does since the address is the room id essentially. So it should work just like direct connects
     
  13. carterdawson

    carterdawson

    Joined:
    Jan 18, 2014
    Posts:
    5
    Exciting project! Thank you so much for creating it and making it open source.

    Caveat to all of the below: Although I'm a pretty accomplished developer in C# and other languages, and know Linux very well, I'm a complete dotnet on linux noob. This project is pretty well geared towards people who already know what they are doing, so my (first) contribution will be to document the process of getting something up and running.

    I'm trying to get it to work, and having some issues. I'm using a standard Amazon EC2 AMI:
    Ubuntu 18.04 AMI with .NET Core 2.1

    When I run the MLAPI.Relay project, I get the following output (NOTE: using the HLAPI template with no mods):

    ubuntu@ip-172-30-0-103:~/MLAPI.Relay/MLAPI.Relay$ dotnet publish
    Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
    Copyright (C) Microsoft Corporation. All rights reserved.

    Restore completed in 72.8 ms for /home/ubuntu/MLAPI.Relay/MLAPI.Relay/MLAPI.Relay.csproj.
    MLAPI.Relay -> /home/ubuntu/MLAPI.Relay/MLAPI.Relay/bin/Debug/netcoreapp2.0/MLAPI.Relay.dll
    MLAPI.Relay -> /home/ubuntu/MLAPI.Relay/MLAPI.Relay/bin/Debug/netcoreapp2.0/publish/
    ubuntu@ip-172-30-0-103:~/MLAPI.Relay/MLAPI.Relay$ LD_LIBRARY_PATH=./Libs dotnet bin/Debug/netcoreapp2.0/publish/MLAPI.Relay.dll
    ================================
    [INFO] Starting relay...
    [INFO] Created message buffer
    [INFO] Created HostTopology
    Killed
    ubuntu@ip-172-30-0-103:~/MLAPI.Relay/MLAPI.Relay$

    NOTE: the two [INFO] messages above "Killed" were added by me to try to track what happens.

    Questions:
    1. Is this the proper way to run the application? (A similar thing happens if I just "dotnet run" from the MLAPI.Relay project directory. Setting the LD_LIBRARY_PATH seems like a pretty esoteric thing to do, so I'm surprised if this is the "correct" way to run the thing.
    2. I'm using .Net Core 2.1 (2.1.302, exactly, just because that's what was easy for me to get running). Does that platform work? I remember seeing someplace that 2.0 was required, but I can't find where I saw that now. Could that be my problem?
    3. If not the version, any sense of what might be going on causing my process to be killed or how to troubleshoot further?
    4. Any plans to open up libUNETServerDLL? it looks like it's dying within the HostTopology class in there. If I could have drilled down into that, I might have been able to understand more or resolve the issue...

    Best regards, and thanks again,

    Shaun
     
  14. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    There is two parts to it. I don't actually know very well how the dotnet application works on Linux. What I do, Is I use Visual Studio to build a Dll. (By selecting Publish, and choosing Linux x86-64). I'm assuming that's what dotnet publish does. Once you have the dll, I just use dotnet <path to dll> to run it.

    This is more about dotnet on Linux. Personally, I don't even like .NET on Linux. What I do is I compile it as a Windows Application and run it with Mono (I prefer Mono over .NET Core). I suggest just reading up on .the NET Core SDK
     
  15. SpindizzyGames

    SpindizzyGames

    Joined:
    Jun 29, 2017
    Posts:
    108
    any benchmark data?
     
  16. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    No, I have no official benchmark data as in the throughput. But it should be very fast. It doesn't do very much and does not copy the payload. It just suffixes metadata with each packet and sends it along.
     
  17. genaray

    genaray

    Joined:
    Feb 8, 2017
    Posts:
    191
  18. Davood_Kharmanzar

    Davood_Kharmanzar

    Joined:
    Sep 20, 2017
    Posts:
    411
    i know this very old thread ...

    but can i use this to connect mobile [client] to mobile [host] as serverless solution??
     
  19. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    Yes, by using a relay server you can connect a mobile client to a mobile host without the need of a dedicated server host. But you will still need to run relay servers.
     
    Joe-Censored and TwoTen like this.
  20. theishiopian

    theishiopian

    Joined:
    Oct 23, 2015
    Posts:
    16
    I've been trying to figure out how to use this and I have no clue what I'm doing. I got as far as building the relay server off the repo, and have no idea what to do next. Im using MLAPI and Match Up for matchmaking. Where do I go from here?