Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Add support for connecting via a hostname instead of IP #3441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop-2.0.0
Choose a base branch
from

Conversation

ShadauxCat
Copy link
Collaborator

Add support for connecting via a hostname instead of IP when using supported versions of unity and unity transport.

Changelog

  • Added: When using UnityTransport >=2.4 and Unity >= 6000.1.0a1, SetConnectionData will accept a fully qualified hostname instead of an IP as a connect address on the client side.

Testing and Documentation

  • No tests have been added. (Manual tests were performed. The CI environment doesn't have "localhost" consistently defined to be able to run automated tests.)
  • Includes edits to existing public API documentation.

Backport

Backport: #3440

…pported versions of unity and unity transport.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no longer any way to know if an endpoint is invalid with this update?
Just wondering why we are deleting tests as opposed to updating them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that FQDNs are supported, there are very few addresses that would be invalid. We could check for things like whitespace or non-printable characters, but that's checking for things the user's unlikely to provide us. The only way to really know if an endpoint is valid is to try to connect to it, and I'd argue that having the same error (failure to connect) for a typo that misspells .com as .con as we do for a typo that adds a space is more consistent behavior.

But there's no way to make StartClient fail because that check is async, and that's what those tests were testing.

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my question is more relating to removing something like this:

        [Test]
        public void UnityTransport_StartClientFailsWithBadAddress()
        {
            UnityTransport transport = new GameObject().AddComponent<UnityTransport>();
            transport.Initialize();

            transport.SetConnectionData("foobar", 4242);
            Assert.False(transport.StartClient());

            LogAssert.Expect(LogType.Error, "Invalid network endpoint: foobar:4242.");
            LogAssert.Expect(LogType.Error, "Target server network address (foobar) is Invalid!");

            transport.Shutdown();
        }

As opposed to just wrapping the part I think you are thinking is no longer valid?

        [Test]
        public void UnityTransport_StartClientFailsWithBadAddress()
        {
            UnityTransport transport = new GameObject().AddComponent<UnityTransport>();
            transport.Initialize();

            transport.SetConnectionData("foobar", 4242);
            Assert.False(transport.StartClient());

#if !HOSTNAME_RESOLUTION_AVAILABLE && !UTP_TRANSPORT_2_4_ABOVE
            LogAssert.Expect(LogType.Error, "Invalid network endpoint: foobar:4242.");
            LogAssert.Expect(LogType.Error, "Target server network address (foobar) is Invalid!");
#endif
            transport.Shutdown();
        }

Where we would still expect the same behavior of the client failing to start if it passed in just "foobar" as the address... which is not FQDN nor an IP... ?

The same would go for DetectInvalidEndpoint.

I am confused about the async part as both UnityTransport.StartClient and UnityTransport.StartServer are non-async methods that are defined within NetworkTransport?

Don't we want to make sure that if you give UnityTransport an invalid address (IP or FQDN) that the transport fails to start?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants