UNET match making without the relay server
Is it possible to add matchmaking to my game without using unity's relay server? Where a player hosts a game and other players can join with a find a match button?
Answer by thegreatzebadiah · Apr 27, 2016 at 06:53 PM
Yes, this is possible. The way I do it is by storing the host's IP in the match name when creating the unet match.
Something like
GetComponent<NetworkMatch>.CreateMatch(matchName + ":" + hostExternalIP, advertiseMatch, matchPassword, "", "", eloScore, requestDomain, OnMatchCreate);
Then when you call ListMatches() and get a response you just split on the ":" to parse the ip from that match name. Set the NetworkManager's networkAddress to the ip and then call StartClient() and it will attempt to directly connect to the host's ip. The relay servers won't be used at all (notice you never even call JoinMatch).
The problem you're going to run into is that anyone behind a router (which is everyone) isn't going to be able to host and be connected to without the relays due to NAT security issues. Basically the router blocks incoming connections from any source that the user hasn't already made an outgoing connection to. The solution to this (if you don't want to use the relay servers) is something called NAT Traversal. It's a method for getting around NAT restrictions and allowing players to host even behind a router, without having to do messy things like manually forward ports in their router settings.
I wrote a plugin that adds NAT Traversal on top of Unity's high level networking api. It seems like exactly what you're looking for. Check it out here: https://www.assetstore.unity3d.com/#!/content/58948
I thought this thread was dead. AWESO$$anonymous$$E!! Thanks so much :)
If we do not use Unity's relay server and use that method you provided, we will not use up Unity's CCU?
I think this is a good workaround but this is still using the relay server to advertise the match. The relay server just isn't involved in the communications for the match itself, but it's still used for the List$$anonymous$$atches() call. Is there any advantage with whats proposed here? Thanx.
Answer by brainz · May 27, 2016 at 12:24 AM
@thegreatzebadiah: Is it possible to do the exact opposite? Make your own matchmaker and there connect the players using Unity's Relay service?
Yep, you just need to pass around the NetworkID of the UNet match as part of your matchmaking system. Clients can then pass it into StartClientAll() to join via relay.
I think you cannot. But you could use your own match making and then create a UNet match between the matched players.
Answer by TheDelhiDuck · Jul 28, 2016 at 02:04 AM
Hi the other problem with this we've found is the player count will be wrong in the returned matches. The client can join the match and not connect to the game via the relay server. It seems they shortly get "booted" from the match, while staying connected to the game. I assume this is because there is no relay server connection. Anyone else found this to be true? And or have figured a work around? I'm thinking of trying to establish a relay server client connection but only using it to send some kind of heartbeat.
I am running into the same issues. After about 30 seconds, the matchmaker server will be automatically cleaned up because of a lack of active connection.
Did you ever find a solution?
Your answer
Follow this Question
Related Questions
UNET with Secure Firewalls 0 Answers
UNET Online Match Making? 1 Answer
Is this possible in unity 0 Answers
MatchInfoSnapshot currentSize returns 1 instead of 0 0 Answers
Managed to set up Multiplayer Online on one Computer, but not on 2 0 Answers