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.
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 =)
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.