feat: Allow Unity Transport to bind clients to a specific port #3764
+44
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose of this PR
Currently Unity Transport always binds clients to an ephemeral port. This is what you want pretty much all of the time, but sometimes there are circumstances that require binding to a specific port. For example if you're in a particularly restrictive environment where your IT team requires knowing the source ports of outbound connections. Or if you're setting up NAT punch-through and need to be able to reach the client on a known port.
This PR adds the possibility of binding to a specific port on the client by adding an extra field to the
UnityTransport.ConnectionAddressDatastructure. For users the API looks like this:I haven't added this new possibility to the UI, and I haven't added new utility
SetConnectionDatamethods that accepts this port as a new parameter. The rationale being that most users do not need to modify this. And putting it in the UI in particular could easily have users thinking that they need to put the server's port in there, which can easily lead to issues with port reuse if you start multiple clients.I also modified the documentation of
SetConnectionDatato make the role of the listen endpoint parameter clearer.Changelog
UnityTransport.ConnectionData.ClientBindPortfield. If not set, clients will bind to an ephemeral port (same as before this change).Jira ticket
None. This is coming from a user request on the discussions website.
Documentation
Testing & QA
Functional Testing
Manual testing :
Manual testing doneAutomated tests:
Covered by existing automated testsCovered by new automated testsDoes the change require QA team to:
Review automated tests?Execute manual tests?Provide feedback about the PR?Backports
Could technically be backported, but I won't bother unless a user requests it specifically.