Search Unity

Resolved Failed to host server

Discussion in 'Netcode for GameObjects' started by grancanon, Apr 6, 2023.

  1. grancanon

    grancanon

    Joined:
    Mar 15, 2022
    Posts:
    12
    Hello everyone!,
    I am trying to create a host from 2 PC with different networks (Online), and I cannot make a connection, on the other hand, with 2 PCs that are within the same network I have no problem.

    I am using my public IP and I have tried with 2 different ports, 7777, and 4380, but it does not work with any of them.

    I don't know what I can be doing wrong, any advice will help me, thanks.

    PS: I attach images to show the configuration:
     

    Attached Files:

  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,888
    You need to setup port forwarding. Your public IP is that of the router. But the router isn‘t running the netcode app. Therefore requests to the given port need to be forwarded to your machine‘s local IP.
     
    grancanon likes this.
  3. grancanon

    grancanon

    Joined:
    Mar 15, 2022
    Posts:
    12
    I understand that I need to open ports as you tell me, but, for example, in the Pico Park game you can play with friends Online and I never had to open ports, how do you make it work without opening ports?
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,888
    The magic ingredient for this is called a relay server. That way there are no direct connections between host and client but all clients and the host actually connect to the relay server, so for everyone involved the connections are only outgoing, not incoming.
     
    grancanon likes this.
  5. grancanon

    grancanon

    Joined:
    Mar 15, 2022
    Posts:
    12
    Do I understand you mean a paid server, or does unity offer a solution to use a relay server for free?

    Thanks
     
  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Unity offers a relay service that is free up to a certain amount of traffic/users, it's here.
    The alternative is using a dedicated server + matchmaker