Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

[Standalone UNET Relay] MLAPI.Relay

Discussion in 'Connected Games' started by TwoTen, Jun 13, 2018.

  1. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,010

    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:
    265
  3. TwoTen

    TwoTen

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

    TwoTen

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

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,010
    Jos-Yule likes this.
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,822
    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,010
    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,010
    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.
     
  9. Jos-Yule

    Jos-Yule

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

    LostPanda

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

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    88
    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,010
    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,010
    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