[Standalone UNET Relay] MLAPI.Relay


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

6 Likes

Ok, setup Ubuntu 18.04 LTS, installed .NET via Microsoft’s docs, and got the 0.0.0.2v of the app. Ran the ./start-relay.sh and got this error - Dropbox

What .NET version?

Resolved in v0.0.0.3

The relay has now been made open source.

2 Likes

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.

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)

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.

1 Like

Hey, this is great, thanks for doing this!

this great,thanks @TwoTen

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…

I think it does since the address is the room id essentially. So it should work just like direct connects

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

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 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

any benchmark data?

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.

@TwoTen I wanna bring this back to live… So we are working with the relay server and we have the following problem… Invokes randomly throw errors… yes, exactly… and that kills the whole gameplay.

https://media.discordapp.net/attachments/563033158480691211/803724646826377226/unknown.png?width=1440&height=178

Any idea what this is caused by ? Those errors dont occur when i host & play local.

i know this very old thread …

but can i use this to connect mobile [client] to mobile [host] as serverless solution??

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.

2 Likes

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?