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

Netcode - Multi hosts - How to check before launch if the port is available?

Discussion in 'Multiplayer' started by Fonsi_123, Apr 20, 2023.

  1. Fonsi_123

    Fonsi_123

    Joined:
    Mar 14, 2023
    Posts:
    4
    Hi, I'm starting to work with Netcode. Why when I run the app as host in unity editor and in another window I run another host in the same configuration, I don't get any port busy errors. It should work like this? I want to be able to create hosts on the same LAN on different devices bypassing the server to save data. Should I use socket broadcast to send data?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    Not sure about the ports issue. That issue may exist but no message is generated since this is a low-level networking issue that may not get routed all the way up to NGO or isn't checked by NGO, hence no log. I'm sure if you used some low-level network traffic analyzing tool you will get to see that there is the issue of identical ports open for connection.

    If you run two host instances with the same port on the same machine and you do NOT get errors regarding "port already in use" this is still a problem because clients will most likely only connect to one of the two instances and there is no way of telling which one - or possibly neither works.

    In order to allow hosting multiple instances on the same LAN you don't have to give users the option of setting the port. Two separate machines can host on the same port because 192.168.0.100:7777 and 192.168.0.200:7777 route accordingly to individual machines. Only if you want a machine to host (or serve) two or more instances then users need to be able to set the port before StartHost/StartServer calls.

    I don't understand the "bypassing the server" part. I think you are either thinking about Lobby or Relay, otherwise you do not have traffic to a remote server for LAN sessions using NGO.

    If using Relay you do have a remote server and continuous remote traffic regardless of what you do, even for LAN sessions. However, for LAN hosting a Relay is not needed and is counterproductive anyway.

    Using the Lobby service for LAN gameplay is (and should be) optional but could work. Once the game starts, traffic will be LAN-only because the Lobby is only for finding and setting up sessions. However, for LAN sessions players expect to be able to have a LAN-only lobby since they may not have Internet connection to begin with.
     
    Fonsi_123 likes this.
  3. Fonsi_123

    Fonsi_123

    Joined:
    Mar 14, 2023
    Posts:
    4
    Thanks for the extensive explanation :) First of all, you reminded me that each device will have a different local IP address, so there shouldn't be a problem with the ports. And some other new things I learned, thanks ;)
     
    CodeSmile likes this.