How to set hosts IP
So, I made a 2D game with the basics of Roll-a-Ball and Multiplayer Networkig tutorials.
The problem is: on one-computer (two clients: one is the host) it works fine, but my friend cant connect to me. I think the problem is that the NetworkManagerHUD always reads the address as "localhost" and port "7777". Can I change it? And how?
Oh, I know how to change it, but in-game? Or can I add a button to change it?
localhost is always 127.0.0.1
You can simply click the box and put a new IP address in, in the build.
First attempt to connect between the editor and a standalone on the same system. If this fails its usually firewall/router related.
Thanks fr the answers, but I already know how to set the address and port in the editor. I just need to change it in-game or something like that. I think you used in your life at once the Network$$anonymous$$anagerHUD, you can type an address to connect to. But in.game, I need to change it, not in the editor. Also, in the editor I tried modifying the IP, with a friend and it did not work. Firewall is off, and I'm stupid in router related things, like "forwarding".
Answer by thegreatzebadiah · Apr 27, 2016 at 09:56 PM
You can change the address that the NetworkManager connects to by setting networkAddress in your code any time before the call to StartClient(). You shouldn't need to set it on the host.
You're still going to have trouble connecting to any host behind a router though due to those pesky "forwarding" issues. You have two options.
Option 1 is to use Unity's expensive relay servers. That means you'll need to use unity's matchmaking stuff. NetworkMatch.CreateMatch() / NetworkMatch.ListMatches() / NetworkMatch.JoinMatch(). Then instead of setting NetworkManager.networkAddress you just pass the match info JoinMatch() to connect.
Option 2 is some sort of NAT traversal solution that will handle port forwarding / punch-through automatically. I recommend my plugin that you can get on the asset store: https://www.assetstore.unity3d.com/en/#!/content/58948 In that case you won't have to worry about creating or joining matches. You just call StartHostAll() to start hosting. You pass the host IP into StartClientAll() to connect. Everything else is handled for you behind the scenes. Ports are forwarded automatically on the host's router, and if that doesn't work there's some complicated puchthrough magic that happens that will usually (85-95%) succeed in connecting players directly. If all else fails you can optionally still fall back to using Unity's relay servers which work 100% of the time (but are expensive).
actually, thanks for answering.
only probelm is i used unity at least 2 months ago, yesterday i downloaded the new update, and everything was weird. so i currently taking another nap.
anyways thanks again and if i get out of my laziness a will read your comment again
Answer by yafo_unity · Aug 22, 2016 at 07:10 AM
hey, Buddy,How do you solve this problem in the end?
check out my other comment on thegreatzebadiah.
basically i didnt solve it. if i will able to get a working multiplayer (i and my friend 100km away) i will post what i did.
you thought i was gone, eh?
well, indeed i stopped program$$anonymous$$g/trying to come up with a simple game idea, but yeah the deal still holds, if it works imma post it (also i was a little stupid back then in 2016, forgive my english)