Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Server port & address?

Discussion in 'Multiplayer' started by any_user, Jun 25, 2015.

  1. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
    Is there a way to know the server port after it has been started (without keeping track of it myself)? I was looking for something like NetworkServer.listenPort, but found nothing..

    I know there is a networkPort property in the NetworkManager, but it's set manually before starting and could be wrong later.

    Also, is there an easy way to get the local (LAN) ip address? The networkAddress property of NetworkManager doesn't help here..
     
    Last edited: Jun 25, 2015
  2. SuperNeon

    SuperNeon

    Joined:
    Mar 16, 2014
    Posts:
    85
    You can find the address in netwok connection.
    I don't know it it contains the port ^^'
     
  3. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    AddHost( ... port.. ) will return -1 if it cannot open socket, or id if can:

    int port = 3333;
    int hostId = AddHost(..., port);
    int i = 0;
    while( hostId ==-1 && ++i < 10 )
    {
    hostId = AddHost(..., ++port);
    }

    What's happened if your pc has more than one network cards and belongs more than one LAN?