Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

[SOLVED] Multiplayer Networking LAN Won't Connect From Another PC

Discussion in 'Connected Games' started by Straynamic, May 11, 2017.

  1. Straynamic

    Straynamic

    Joined:
    May 11, 2017
    Posts:
    3
    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:
    https://unity3d.com/learn/tutorials/topics/multiplayer-networking

    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.

    Thanks!
     
    Last edited: May 11, 2017
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,785
    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.
     
  3. Mendys

    Mendys

    Joined:
    May 12, 2017
    Posts:
    1
    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 :/
     
  4. Straynamic

    Straynamic

    Joined:
    May 11, 2017
    Posts:
    3
    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.

    Any thoughts?
     

    Attached Files:

  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,785
    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.
     
  6. Straynamic

    Straynamic

    Joined:
    May 11, 2017
    Posts:
    3
    Thank you for the help, I've gotten the game to successfully run on LAN. Guess the next fun part is to get internet play working. Wish me luck!
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,785
    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.

    Good luck!
     
  8. wolfgang7913

    wolfgang7913

    Joined:
    Apr 25, 2017
    Posts:
    3
    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.
     
  9. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,009
    Well, then you need to use a relay or try to use STUN to punch through the NAT
     
  10. wolfgang7913

    wolfgang7913

    Joined:
    Apr 25, 2017
    Posts:
    3
    Explain? That really makes no sense to me and a google search of what you said brings no relevance.
     
  11. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,785
    TwoTen is saying if you cannot use port forwarding because you have no access to your router, you have two alternatives.

    1) 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.
    2) 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.
     
  12. kweiming

    kweiming

    Joined:
    Jun 18, 2017
    Posts:
    7
    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:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine.Networking;
    4. using UnityEngine.Networking.NetworkSystem;
    5. using UnityEngine;
    6.  
    7. public class NetworkServerUI : MonoBehaviour {
    8.  
    9.     void OnGUI(){
    10.         string ipadress = Network.player.ipAddress;
    11.         GUI.Box (new Rect(10,Screen.height-50, 100, 50),ipadress);
    12.         GUI.Label (new Rect(20,Screen.height-35, 100, 20), "Status: "+ NetworkServer.active);
    13.         GUI.Label (new Rect(20,Screen.height-20, 100, 20), "Connected: "+ NetworkServer.connections.Count);
    14.     }
    15.     // Use this for initialization
    16.     void Start () {
    17.         NetworkServer.Listen (7777);
    18.     }
    19. }
    20.  
    the client:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine.Networking;
    4. using UnityEngine.Networking.NetworkSystem;
    5. using UnityEngine;
    6.  
    7. public class NetworkClientUI : MonoBehaviour {
    8.  
    9.     NetworkClient client;
    10.     void OnGUI(){
    11.         string ipaddress = Network.player.ipAddress;
    12.         GUI.Box (new Rect(new Rect(10, Screen.height - 50, 100, 50)), ipaddress);
    13.         GUI.Label (new Rect(20, Screen.height - 30, 100, 20), "Status: "+ client.isConnected);
    14.  
    15.         if(!client.isConnected){
    16.             if(GUI.Button(new Rect(10, 10, 60, 50), "Connect")){
    17.                 Connect ();
    18.             }
    19.         }
    20.     }
    21.  
    22.     // Use this for initialization
    23.     void Start () {
    24.         client = new NetworkClient ();
    25.     }
    26.  
    27.     void Connect(){
    28.         client.Connect ("192.168.0.3", 7777);
    29.     }
    30.    
    31.     // Update is called once per frame
    32.     void Update () {
    33.        
    34.     }
    35. }
    36.  
    the server side doesn't get any connection and client can't connect to the Server IP
    does anyone know what's going on?
     
  13. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    719
    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.

    P.S. NAT Traversal is on sale now for 30% off :)
     
  14. Russellinho

    Russellinho

    Joined:
    Jan 1, 2016
    Posts:
    6
    Jerry Stackhouse
     
  15. ayyanchira

    ayyanchira

    Joined:
    Nov 24, 2017
    Posts:
    2
    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???
     
  16. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,785
    First thing I'd verify is that your Windows firewall settings aren't preventing the connection.
     
  17. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    366
    The WIndows Firewall settings are defintely a PITA !
     
  18. Bleggaman

    Bleggaman

    Joined:
    Dec 4, 2015
    Posts:
    3
    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?
     
  19. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    366
    to do exactly what you say with "new" unity networking, you use the "network discovery" component.

    it is a lot of work :/
     
  20. Bleggaman

    Bleggaman

    Joined:
    Dec 4, 2015
    Posts:
    3
    ha, ya. that sounds like quite the tedious task.
    Does that interface with the LLAPI?
     
  21. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,785
    I wasn't suggesting running ipconfig within your build (though to answer the question, you could do it with System.Diagnostics.Process). I was just suggesting that command to get your host's IP address, which you'd enter into the client to connect to, because you need to provide your client with the address of the host in order for it to know where to connect to.

    To avoid having to manually enter IP addresses into the client you'd do that with one of several methods. As already mentioned you can use network discovery for finding servers on the local network. You could also go the server browser direction, where you have a dedicated server that other game servers register themselves with, and that clients can use to find servers to connect to. You could also try cloud services with built in lobby or matchmaking.
     
  22. Mr_Perlful

    Mr_Perlful

    Joined:
    Dec 21, 2016
    Posts:
    6

    there is a possibility you may need a key, i write my own servers for mp so im not 100 percent sure there.

    have you tried running the .exe for your game on both pc's? or did you run one from unity and the other from a client?
    i find running the "server" via the unity editor it wont pop my firewall permission message to allow access for the game, but when i run the client the permission message appears perfectly fine and im able to connect with no issues.
     
  23. JMasterChief

    JMasterChief

    Joined:
    Dec 15, 2016
    Posts:
    27
    I'm using uMOBA asset from unity store and having the same problem. I entered correct ip host's address (not the 127.0.0.1), but it still won't connect to the port server..

    You don't even need to code, you just need to enter in the blueprint.

    It seems Unity don't know how to read numbers other than letters, to me.
     
  24. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    366
    HI @JMasterChief

    unfortunately it's very unlikely you'll get MP working with some kit.

    Here is a HUGE post about some networking woes,

    Note that "incidentally" at the bottom it explains exactly how to do the client and server side of discovery.

    https://forum.unity.com/threads/net...lient-disconnect-error-1.439245/#post-3754939

    Hope it helps!

    Don't forget as mentioned on this page, one "ridiculous" problem that is a hangup, you have to absolutely totally turn off all the firewalls on your PCs/Macs during development. Good luck!
     
  25. JMasterChief

    JMasterChief

    Joined:
    Dec 15, 2016
    Posts:
    27
    uMOBA claims they have PvP feature, and server all in its asset. I mean all these Blizzard, Overwatch, must have started from SOME game engine. Anyone resourceful here?
     
  26. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    933
    No you don't, you just have to understand how to configure port forwarding or DMZ for your router (if you want to accept connections from external networks) and you just need to correctly configure the software firewall rules in Windows/OSX.

    Anyone developing a networked game really ought to take time to learn enough about networking in general (at least) to do the above, it's going to be a struggle otherwise.

    Using something like PUN usually removes the immediate need to know this stuff, but if something isn't working, having the knowledge to diagnose network problems will be a big help in solving connection problems.