Networking: Ports and how important are they?

in the Network.InitializeServer() function, what exactly is the function of the port? is it any random number used to identify it from other servers? and what is the range of port numbers? like what’s the minimum port number and what’s the maximum port number. my point is so that when my clients press a button with the name “Connect”, they’ll send a message to my Server scene that should increase the current port number if the current server is full, and create another server on my computer.

  1. is that possible / feasible?
  2. is it practical or is there a better way?

the reason why i want to do that is so that I can make a multiplayer where a set amount of players can connect with each other, but the servers “controlling” or more accurate, supervising, the clients are on my computer so that it saves all the data to my computer. so basically my questions are:

  1. what’s the limits of the port numbers, and
  2. is my approach correct or even possible?

Thank you! :smile:

A port is used to differentiate different applications.

For example a server uses port 80 for web pages, while using 25 for mail hosting. A client (e.g. a webbrowser) uses a random port to talk to that server.

To pick a port number I’d pick a random ‘registered’ port and do a goolge to see if anyone uses it. If your really bothered there is a list of what ports have officially been registered or not IIRC.

If you have multiple servers on a PC, then they all need to use different ports. However, it is possible to have 1 server, that simply receives messages and forwards them to ‘rooms’ - this is how photon for example does it.

oh, ok, so according to your response, the best thing I would try is the Room feature, and so I guess I’d make a virtual parameter in the client script that sends an RPC to the server script to say that client and say 1 friend for 2-players, is in room “So_And_So” and the players in that ‘room’ can only see (update) the other players in that ‘room’?

That seems pretty dynamic. but a problem I can see is that there’s 1 scene for each multiplayer level. and there’s going to be several teams of 2 people, so is there a way to make it so the players in their own ‘room’ can only affect the players or objects in their own room… is that possible? or would I have to make a generic RPC function with a parameter like “string room, NetworkView[ ] players” would that work? or is there a better way? (I’d like to keep it Unity Network, as you can see.)

if i put in a script when making a server with my externalIP and externalPort, are the numbers that it gives accessible from other computers sat across the country or world?