Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity ports and custom server setup

Discussion in 'Multiplayer' started by Dabookman, Nov 25, 2009.

  1. Dabookman

    Dabookman

    Joined:
    Oct 20, 2009
    Posts:
    17
    I have a couple of questions about setting up custom servers and how Unity deals with ports.

    I currently have a project that has very basic LAN multiplayer: one pc starts a server (it's essentially dedicated as no player instance is spawned and the server can only watch the scene), and other pc's connect directly to it via its IP address and port.

    The default port I used was 25001 and it has also been forwarded to our router.

    Now, when attempting to access the server over the internet, nothing happens, even with NAT functionality.

    I was wondering if this may have something to do with the port? Would Unity use only port 25001 as specified for all communications? Or does it open other ports after establishing the initial connection?

    I'm kind of out of my depth with this stuff, so any help or pointers would be greatly appreciated and I can upload the file if need be.
     
  2. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    you specify the port in the CreateServer(...) function and can be pretty much any portnumber, well any 16-bit number anyway (its always good to check up on IANA.com, to avoid common ports) usually anywhere from 5000 to 48000 or so should be pretty "safe" port numbers.

    Remember its your extern ip address that internet users has to connect to which might (or most certainly will, if you have a router) differ from your local ip address.

    You have to setup your router to forward udp packets sent on your games port and not tcp packets (not 100% sure if unity uses tcp for anything), but just to be sure choose both =)

    //Perlohmann
     
    Den56 likes this.
  3. Dabookman

    Dabookman

    Joined:
    Oct 20, 2009
    Posts:
    17
    Thanks for the reply, I figured it out through more fiddling but your right I was missing the UDP forwarding of my ports (Had TCP). Thanks very much!
     
  4. sriyan

    sriyan

    Joined:
    Aug 5, 2013
    Posts:
    1
    I pretty much have a similar issue where in I use Network.IntializeServer() with a port number (#19191) and then have other hosts (players) getting connected to it.

    Then in code I go about using Network.Instantiate() and then use RPCs here an there, as needed.

    Now this works fine on a normal router config / LAN.

    But in production, there seems to be an issue when the games tries to do a multi-player connectivity to sync data across. The environment has its own nature in production such as NAT enabled, firewall blocking etc.

    Question: Is that only 19191 that I would have to enable port forwarding for UDP or would Unity use other ports to have the data synced using it Network frame work. If so what is the range of ports that I have to enable. Also, it there a way I can configure Unity to use a specified range.