Hi everyone,
I’m pretty new to the whole networking scene, but still trying to find my way.
So, I’ve been following the simple networking tutorial Unity has:
It works great and as intended on a single pc. I can control two players in different instances of the game. However, when I attempt to run the game on two different computers on the same network (wifi or grounded), it doesn’t pick up the other.
Now, I’ve had this problem for quite some time, searched high and low on YouTube, and the forums. I’ve found similar problems, but have yet to find a solution. Any help in the right direction would be greatly appreciated.
Your problem could be as simple as accidentally using 127.0.0.1 instead of the game host’s IP address, or as complicated as having to go through your individual app firewall settings. Can’t tell you more if all the information you’re willing to provide is the fact it doesn’t work.
Im having the same problem, i tried with connecting to the server by the local IP adress (192.168… etc) it just wont work, i found some people talking about getting a UNET key or something bu the unity page corelated to that wont open for me
Alright, sorry for being a bit vague before, Here’s what I could gather so far:
Attached is how I have my Network Manager set up. (Uses localhost and port 7777)
I’ve allowed the app to run through my home network on both computers, through the firewall, and has even been disabled. No other firewall should be interfering.
I’ve port forwarded 7777 as TCP and UDP, with no success.
The problem visualized is: On one computer, I can select: LAN HOST(H), and control my player
On the other computer, I can select: LAN Client(C) (Which is set to localhost)
The result displays: “Connecting to localhost:7777” , and then times out.
Localhost is your problem. You need to connect to the ip address of the host computer. localhost (which is the same as connecting to 127.0.0.1) means connect to the computer I am on. Run ipconfig or ifconfig on your host computer to see what IP address it is using, and on your clients you connect to that. If you are trying to connect with another computer over the internet it is far more complicated, where you’ll need to log into your router and find its IP address and port forward to your host computer.
So generally what you would do is if you are hosting the game on your computer, log into your router and forward the port from the router to your host computer’s IP address. It can be helpful to give your host computer a static IP address first so this address doesn’t change. Judging from the image you posted, you probably just need to forward UDP port 7777. You also need to check on the router what internet IP address it received, often called a public, Internet, or external IP address. This is the address your remote clients will use to join your game.
Did you ever figure this out? I can’t connect to my other computer, and I tired using my ip address. Port forwarding 7777 isn’t really an option given that I am on a college ethernet. PLEASE HELP, this is driving me mad.
TwoTen is saying if you cannot use port forwarding because you have no access to your router, you have two alternatives.
Use a relay service so all clients, even a client acting as a host, only need to establish outbound connections. Unity provides one as a pay for what you use service as part of Unity Multiplayer. Photon Cloud is an alternative service and networking API you could consider instead of Unity Multiplayer.
Use a technique called NAT Punch through. There’s a pay for package on the Unity Asset Store that does this, but it appears to be designed to compliment the Unity Multiplayer relay service, as NAT Punch through does not work 100% of the time.
There is a 3rd alternative where you could host game servers in a datacenter. Basically rent a VPS or dedicated server and run your server code there.
It’s weird that I can’t run my game on LAN with my two computers.
the server IP is 192.168.0.3 both computers on under same WIFI
the server side:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;
using UnityEngine;
public class NetworkServerUI : MonoBehaviour {
void OnGUI(){
string ipadress = Network.player.ipAddress;
GUI.Box (new Rect(10,Screen.height-50, 100, 50),ipadress);
GUI.Label (new Rect(20,Screen.height-35, 100, 20), "Status: "+ NetworkServer.active);
GUI.Label (new Rect(20,Screen.height-20, 100, 20), "Connected: "+ NetworkServer.connections.Count);
}
// Use this for initialization
void Start () {
NetworkServer.Listen (7777);
}
}
the client:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;
using UnityEngine;
public class NetworkClientUI : MonoBehaviour {
NetworkClient client;
void OnGUI(){
string ipaddress = Network.player.ipAddress;
GUI.Box (new Rect(new Rect(10, Screen.height - 50, 100, 50)), ipaddress);
GUI.Label (new Rect(20, Screen.height - 30, 100, 20), "Status: "+ client.isConnected);
if(!client.isConnected){
if(GUI.Button(new Rect(10, 10, 60, 50), "Connect")){
Connect ();
}
}
}
// Use this for initialization
void Start () {
client = new NetworkClient ();
}
void Connect(){
client.Connect ("192.168.0.3", 7777);
}
// Update is called once per frame
void Update () {
}
}
the server side doesn’t get any connection and client can’t connect to the Server IP
does anyone know what’s going on?
Hey, that’s me! And yeah, NAT Traversal is only meant to compliment the relays. There are scenarios where it can not work and the relays are the only option. That’s just the unfortunate reality of the internet as it is today. IPv6 will solve most of these issues in the long run with end-to-end addressability, but it’s a long way off still and even with IPv6 some networks like in schools and corporate intranets will likely go out of their way to restrict things so I don’t think relays are going anywhere for a long time as a requirement for peer-hosted games.
I am facing a problem where I am trying to connect a project in Windows Laptop with the one on MacBook. They both are on same WiFi network.
When I create a server on Mac, and then try to connect it via windows, it properly spawns a player. However, the opposite is not happening. I am NOT able to keep Windows as a server machine. The Mac Unity shows ‘connecting…’ but doesn’t connects at all.
If I run terminal and write ping 192.168… it is giving response, but Unity is not able to find that windows PC. Any idea what could be the problem???
Hey, this is awesome advice. How do you run ipconfig from within a unity project though?
My game is a multiplayer game where the players connect by lan and one of them is the host (connected to themselves as the local host). My biggest concern is that people are going to start it up, and the first thing they see is IP stuff and Host/Client stuff, which i believe is a deterrent. So, I would like to at least have this structure to make the process of starting the game as easy for the players as possible:
You open game and you see host or client. The one person who chooses host sees an IP address that the clients copy and past into their games- then everyone connects to the host and they begin the game. yay!
Seems like running ipconfig would be great, but the players shouldn’t have to use command line stuff for playing our game. So, how could i get the host’s IP address from within the c# script to avoid the complication for the players?