Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Authoritative server trying to connect to unknown IP

Discussion in 'Multiplayer' started by terresquall, Jan 24, 2015.

  1. terresquall

    terresquall

    Joined:
    Mar 2, 2014
    Posts:
    29
    Hello all,

    I'm creating a simple multiplayer game with an authoritative server on Unity, and I've run into a little snag. Here's basically my script for the authoritative server setup:

    Code (csharp):
    1. void OnGUI() {
    2.         GUI.skin = UISkin;
    3.         if(IsServer) {
    4.             if(Network.peerType == NetworkPeerType.Disconnected) {
    5.                 if(GUI.Button(new Rect(Screen.width*0.25f,Screen.height*0.5f,Screen.width*0.5f,Screen.height*0.1f),"Initialise Server")) {
    6.                     Network.InitializeServer(8,25000,!Network.HavePublicAddress());
    7.                     ServerIPAddress = Network.player.ipAddress;
    8.                 }
    9.             } else {
    10.                 GUI.Label(new Rect(Screen.width*0.25f,Screen.height*0.02f,Screen.width*0.5f,Screen.height*0.1f),"Server Address: "+ServerIPAddress);
    11.             }
    12.         }
    13.     }
    My authoritative server currently only has an <InitialiseServer> button, and when you click on it Network.InitializeServer() is called and the IP address shows on the screen to tell clients who to connect to.

    My question is this: when the server is initialised, about 10 seconds or so later (without any clients connecting), a runtime error would be thrown saying:

    The connection request to xx.xxx.xxx.xx:50005 failed. Are you sure the server can be connected to?

    Why is this the case? I'm not making any connections to anywhere else in my server OR client script. Should I be concerned?

    EDIT: I'm asking these questions because the IP address shown in the error isn't my IP address, and I'm using port 25000. That's why I find it quite strange.
     
    Last edited: Jan 25, 2015
  2. Christian-Tucker

    Christian-Tucker

    Joined:
    Aug 18, 2013
    Posts:
    376
    First, I would recommend removing your IP-Address from the post.

    Second, make sure that you have port 50005 forwarded. Look up port-forwarding if you're confused.

    If you just want to connect for testing on the local machine, use localhost instead of xx.xxx.xxx.xx
     
  3. DLGScript

    DLGScript

    Joined:
    Jul 15, 2012
    Posts:
    272
    And what if I want to test it on public IP so my friends will connect to for testings?
    Which IP and Port do I need to use?
     
  4. Christian-Tucker

    Christian-Tucker

    Joined:
    Aug 18, 2013
    Posts:
    376
    You'll need to use your external port, you can find this at "whatismyip.com" and numerous other websites, any open port will usually suffice.
     
  5. terresquall

    terresquall

    Joined:
    Mar 2, 2014
    Posts:
    29
    That actually isn't my IP address. I'm initialising my server on yyy.yyy.y.yyy:25000 but Unity throws an error with the address of xx.xxx.xxx.xx:50005. Any insight on why that is the case?
     
  6. DLGScript

    DLGScript

    Joined:
    Jul 15, 2012
    Posts:
    272
    I can't find my Port in this website as you said, I can only see there my IP
    How can I find which open port I have?
     
  7. Christian-Tucker

    Christian-Tucker

    Joined:
    Aug 18, 2013
    Posts:
    376
    You have to open one manually, look up port forwarding.
     
  8. AustinRichards

    AustinRichards

    Joined:
    Apr 4, 2013
    Posts:
    321
    That's all the code in your project? You have no other code connecting to the other port being accidentally initialized?