I have start develop a multiplayer game with 8 players per game. I can’t pay for unity’s matchmaker services so i want to create a button that start a server on the client, then pass his ip and port to a txt files stocked on a server then each player can join him with Network.Connect
I know how to connect player and how to use the network manager but i don’t know how to make client start hosting and allow other computer to connect to him. I have made some research on internet and i have understand that i need to do “port forward” but i don’t really know how and what is it.
Port forwarding is something you do in your router to tell the “outside” world that a certain internal ip address (and port) should receive (types) of incoming data.
If you had 3 computers and wanted 1 to receive the game, you’d forward the port and that PC’s ip address in the router, so when you play the traffic goes there. It’s pretty easy once you find it in the router config panel
As for setting up the connections, if you already know how to do that, as far as I know - whenever I’ve done this - I have to tell anyone connecting what the ip address is. There’s no way for a host to tell other people automatically.
There is also UPNP for routers, and I do not know how to do it personally, but I know you can write something for that, probably beyond the scope here
I’m not sure whether the matchmaking service has to be paid during development / for a small amount of players, but I believe you can use the 20 CCU for testing purposes. So if you only need to test atm, you should be fine using that.
Alternatives:
If you want to provide a comfortable solution, you’d probably either go for
hole punching
3rd party/custom “relay” server implementation
If you want to be less user-friendly, you’d go for port forwarding or a 3rd party tool that kind of creates a “network” that all clients can be a part of, as if they were connected within the same LAN + subnet.
Im only student so i can’t pay for unity’s relay/matchmaker. I will try hole punching but i don’t know how. I only need to pass host ip and port to all player who want to join ? Or is it mire complicated ?
Just read it up.
But either way you’ll need some mechanism to share information about matches, basically some kind of service to query the matches which are available.
Still, somewhere I’ve read that you won’t need to pay for testing purposes and the website does also suggest it. I’m not completely sure whether this includes such services but you may just attempt to find out a little more about it.
I am curious, though, when you brought up being a student - is this a project for school or yourself?
Related (or not) – Do you need a lobby?
Reason for asking: If this is a school project, and you have to create a multiplayer game, but there’s no requirement for a lobby, the advice may differ.
It’s a school project but we are free to do what we want. I want to make a lobby but i have already done this. I don’t want to use free unity matchmaker because the live mode is paid only. I think i will query match info in a sql database. I will test this tomorrow.
Okay, it’s take more time than what i was thinking but anyway, this work localy (whis 2 computer on the same network) but this doesn’t work if anyone is not on the same network. I have check on http://www.canyouseeme.org/ and the port is not forwared. I don’t know if it’s normal. How can i allow peaples to host game and other join them ?
In order for two people to connect to each other without an intermediate server you have to either open the port manually or handle NAT punchthrough in your application. Typically NAT punch requires servers somewhere but I think there is some asset on the store that handles it automagically.
I’m still watching this thread. It’s a project and you want to get it to work. Just enable port forwarding and continue with your work That’s by far the simplest solution.
It’s a school project but i want to make it a real game that we can play with friends. Either the unity relay don’t allow real time networking without paying. Thanks for your reply, i will buy the asset.
I’m only pushing the point because if you do your own networking you’re going to have to write a ton of boilerplate code just to get off the ground. Why do that when you can use what’s integrated into the engine already?