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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Can you send a packet without connecting first? (NAT Punchthrough)

Discussion in 'Unity Transport' started by Kapistijn, Dec 3, 2021.

  1. Kapistijn

    Kapistijn

    Joined:
    May 20, 2014
    Posts:
    4
    Hi everyone,

    I've been using the com.unity.transport layer for a good week now and I've enjoyed working with it so far. For me it's the perfect balance between a "low level" & "high level" networking framework.

    However for the past couple of days I've been wrapping my head around NAT Punchtrough in order for players to allow to connect to eachother without port forwarding.

    After reading up on many great articles such as:
    https://keithjohnston.wordpress.com/2014/02/17/nat-punch-through-for-multiplayer-games/
    https://bford.info/pub/net/p2pnat/

    And reading though source repositories of implementations such as:
    https://github.com/MidLevel/MLAPI.Puncher

    I've come to the conclusion that the game server needs to be able to send packets from the same public port as it is listening to.

    But the only packet you can send without establishing a connection first is... a connect packet.
    So my question is: Can you send a packet without connecting?

    Because when you send a connection packet from a new NetworkDriver, it uses a different external port than the one listening (logical, I think). And when I want to bind the same port as the NetworkDriver that is listening it doesn't work.

    Sending a connect message from the NetworkDriver that is listening is also not really working. (and feels very awkward anyway)

    So is there a way to do this? Or any other way to implement NAT Punchthrough with this transport layer? (I would prefer not to mix multiple networking layers)

    Thank you guys so much in advance!

    EDIT: Mayor edit as I've done more research.
     
    Last edited: Dec 6, 2021
    iclosed likes this.
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    150
    Unfortunately, there isn't really a way to send data in UTP without establishing a connection first.

    Currently to connect two peers that are both behind NAT, we support connections through the Unity Relay service. Otherwise we don't really have a good story regarding NAT punch-through at the moment.
     
  3. Kapistijn

    Kapistijn

    Joined:
    May 20, 2014
    Posts:
    4
    Thanks for your reply!

    Do you have any idea if this will ever be supported or does it go against the architecture of the transport package? (as it's build upon the connectionless protocol UDP)

    EDIT: Fixed my post as I found out that UTP stands for Unity Transport Package
     
    Last edited: Dec 7, 2021
  4. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    150
    Can it be supported? Yes. Technically speaking, there's nothing that would prevent UTP from implementing NAT punch-through. In fact, it's probably possible (but not necessarily easy) to implement your own through a custom
    INetworkInterface
    (maybe something that wraps the default
    BaselibNetworkInterface
    ). These are uncharted waters, though.

    Now will it ever be supported? I quite frankly have no idea (sorry!).
     
  5. Kapistijn

    Kapistijn

    Joined:
    May 20, 2014
    Posts:
    4
  6. PolarTron

    PolarTron

    Joined:
    Jun 21, 2013
    Posts:
    56
    NAT Punchthrough is a must have feature for UTP and I can't believe it's just under consideration after 1.0
    I can't even connect to other computers on the same office network because of the firewall.

    I know a small % of players can't do NAT Punchthrough so I understand the need for Unity Relay, but as things are now almost all players need to use Unity Relay.

    Just like LiteNetLib, RakNet, SteamNetworkingSockets etc... I would like this to be a core feature in UTP.
     
    Sirius64 likes this.
  7. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    150
    Thanks for your feedback. The roadmap that Kapistijn linked to allows voting on items (and submit new ones). These votes are taken into account when deciding what to work on next, so if you feel strongly that NAT punchthrough is a critical feature for UTP, I invite you to indicate so on the roadmap.
     
    PolarTron likes this.