EllanJiang/GameFramework · error · GameFrameworkException

Not supported address family

Error message

Not supported address family '{0}'.

What it means

During Connect, NetworkChannelBase resolves the host address and checks its SocketAddress AddressFamily against what the socket supports. If the address family is unsupported (e.g. an IPv6-mapped/unexpected family on an IPv4-only socket), the channel raises NetworkChannelError with NetworkErrorCode.AddressFamilyError; if no error handler is subscribed, it throws the GameFrameworkException carrying 'Not supported address family {0}'.

Solutions

  1. Subscribe to NetworkChannelError and handle AddressFamilyError instead of relying on the thrown exception.
  2. Connect using an explicit IPv4 (or matching-family) address, or resolve the hostname and pick an address whose AddressFamily the channel supports.
  3. Enable IPv6 support on the platform/socket configuration, or force IPv4 resolution (e.g. prefer A records) to match the channel.

Example fix

// before
channel.Connect("example.com", 8080); // resolves to IPv6, socket is IPv4-only, no error handler

// after
channel.NetworkChannelError += (c, code, se, msg) => Log.Error(msg);
var addrs = Dns.GetHostAddresses("example.com");
var ipv4 = Array.Find(addrs, a => a.AddressFamily == AddressFamily.InterNetwork);
if (ipv4 != null) channel.Connect(ipv4.ToString(), 8080);
Defensive patterns

Strategy: try-catch

Validate before calling

var addrs = Dns.GetHostAddresses(host);
if (!addrs.Any(a => a.AddressFamily == AddressFamily.InterNetwork || a.AddressFamily == AddressFamily.InterNetworkV6))
    return; // no usable address family
channel.Connect(host, port);

Type guard

static bool IsSupportedFamily(IPAddress a) => a.AddressFamily == AddressFamily.InterNetwork || a.AddressFamily == AddressFamily.InterNetworkV6;

Try / catch

channel.NetworkChannelError += (c, errorCode, socketError, msg) =>
{
    if (errorCode == NetworkErrorCode.AddressFamilyError)
        Log.Error("Unsupported address family: " + msg);
};
// and/or wrap the direct call:
try { channel.Connect(host, port); }
catch (GameFrameworkException ex) { Log.Error("Connect failed: " + ex.Message); }

Prevention

When it happens

Trigger: Calling Connect with an address whose AddressFamily is not InterNetwork/InterNetworkV6 as expected by the channel, e.g. connecting to an IPv6 literal or hostname resolving to AAAA records on a system/socket configured for IPv4 only.

Common situations: Dual-stack environments where a hostname resolves to IPv6 while the server only listens on IPv4; hardcoded IPv6 addresses on IPv4-only build targets; DNS changes returning a different family than during development.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/9d0b1fa47c4953f5. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Network/NetworkManager.NetworkChannelBase.cs:358

                switch (ipAddress.AddressFamily)
                {
                    case System.Net.Sockets.AddressFamily.InterNetwork:
                        m_AddressFamily = AddressFamily.IPv4;
                        break;

                    case System.Net.Sockets.AddressFamily.InterNetworkV6:
                        m_AddressFamily = AddressFamily.IPv6;
                        break;

                    default:
                        string errorMessage = Utility.Text.Format("Not supported address family '{0}'.", ipAddress.AddressFamily);
                        if (NetworkChannelError != null)
                        {
                            NetworkChannelError(this, NetworkErrorCode.AddressFamilyError, SocketError.Success, errorMessage);
                            return;
                        }

                        throw new GameFrameworkException(errorMessage);
                }

                m_SendState.Reset();
                m_ReceiveState.PrepareForPacketHeader(m_NetworkChannelHelper.PacketHeaderLength);
            }

            /// <summary>
            /// 关闭连接并释放所有相关资源。
            /// </summary>
            public void Close()
            {
                lock (this)
                {
                    if (m_Socket == null)
                    {
                        return;
                    }

View on GitHub (pinned to d0c010b051)