Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Netcode port forwarding not working

Discussion in 'Netcode for GameObjects' started by DarknessNinjaBR, Aug 4, 2023.

  1. DarknessNinjaBR

    DarknessNinjaBR

    Joined:
    Oct 31, 2015
    Posts:
    4
    Hey Guys, I'm doing a personal project, and I wanted to share it with my friends to play with me, I integrated the Netcode in the project, and locally everything works fine, but for some reason, looks like the port forward is not working, I'm using yougetsignal to check if the port is open, but it's always closed
    upload_2023-8-4_13-31-36.png
    I already tested with a lot of IPs, my local IP, public IP, 0.0.0.0 and 127.0.0.1, but neither of this worked
    upload_2023-8-4_13-32-6.png

    and for some weird reason, if I fill the "Override Bind IP" with my public IP, it says the port is already taken
    upload_2023-8-4_13-33-53.png

    The port foward is working fine, I host some Minecraft servers to play with my friends with no issues, I even tried to use the port 25565 in the netcode, but no success

    Someone knows what I'm doing wrong?

    Thank you!

    upload_2023-8-4_13-36-54.png
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,195
    If I remember correctly, you need to set the server's listen address to 0.0.0.0 in code (there is no setting in the Inspector for this - unless this override bind ip is the listen address):
    Code (CSharp):
    1. NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(
    2.     "192.168.15.50", (ushort)7777, "0.0.0.0"
    3. );
    On the router's side forward port 7777 (UDP) to 192.168.15.50
     
  3. DarknessNinjaBR

    DarknessNinjaBR

    Joined:
    Oct 31, 2015
    Posts:
    4
    Hi @CodeSmile Thank you so much for your reply, I really appreciate it!

    This is the Port Forward setup:


    And I used the code you provided in the void Start:
    upload_2023-8-5_10-3-48.png

    But no success : /
    upload_2023-8-5_10-15-9.png
    I tried to generate a build and host using it, but the port still closed
    I also tried using other IP's in the code, I tried to invert it, but neither worked

    Any other ideas?

    Thank you so much!
     
  4. Nyphur

    Nyphur

    Joined:
    Jan 29, 2016
    Posts:
    69
    We found port forwarding alone unsuitable for NGO, we managed to get it through on the local network by providing the local network IP as you have done above but couldn't get it to work via the internet. There were several suggestions from various employees on the forum and none of them made any difference on an external network, in the end we gave up and solved it by just using the Unity Relay system to connect the players, along with the Unity Lobby system. Sorry that this isn't very useful, but it was just my experience with it.
     
  5. DarknessNinjaBR

    DarknessNinjaBR

    Joined:
    Oct 31, 2015
    Posts:
    4
    @Nyphur Thank you so much for your reply!

    I'll be honest, I just created this post because I thought people just gave up, or they had the solution but forgot to share hahaha, sadly is the first option
    I was refusing myself that there is no solution because the code was already working
    But anyway I'll use Unity Relay to make it work

    Again, thank you so much!
     
  6. Nyphur

    Nyphur

    Joined:
    Jan 29, 2016
    Posts:
    69
    No worries, if anyone does manage to get port forwarding to work online let me know! I believe the issue is actually NAT punch-through as I've not seen anyone get it working reliably without Relay or something similar.