EllanJiang/GameFramework · error · GameFrameworkException

Socket is not active.

Error message

Socket is not active.

What it means

Send<T> verifies m_Active after checking the socket exists. m_Active is false when the socket has been created but the channel was closed/disposed or never fully activated, so the packet cannot be enqueued. GameFramework throws GameFrameworkException (or fires NetworkChannelError with NetworkErrorCode.SendError).

Solutions

  1. Listen to NetworkChannelClosed/disconnect events and stop sending once the channel is closed; reconnect before sending again.
  2. Check that the channel is active (or your own connected flag) before each Send call.
  3. Recreate the channel with NetworkManager.CreateNetworkChannel and Connect again if it was closed.
  4. Guard Send calls against concurrent shutdown (do not send from other threads while disposing).

Example fix

// before
channel.Send(chatPacket); // throws after close
// after
if (isConnected) { channel.Send(chatPacket); } else { Reconnect(); }
Defensive patterns

Strategy: validation

Validate before calling

public static bool CanSend(INetworkChannel ch) => ch != null && connectedChannels.Contains(ch); // remove on NetworkChannelClosed

Type guard

public static bool IsActive(INetworkChannel ch) => ch != null && !closedChannels.Contains(ch);

Try / catch

try { channel.Send(packet); } catch (GameFrameworkException ex) when (ex.Message == "Socket is not active.") { ReconnectAndRequeue(packet); }

Prevention

When it happens

Trigger: Calling Send after the channel was closed (Dispose/shutdown sets m_Active false); sending on a channel whose connection dropped and was deactivated; calling Send concurrently with channel close.

Common situations: App keeps a stale channel reference after the server closed the connection and tries to send the next message; sending during scene teardown while the network component is being destroyed; send/recv races around Dispose.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

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

                    if (NetworkChannelError != null)
                    {
                        NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);
                        return;
                    }

                    throw new GameFrameworkException(errorMessage);
                }

                if (!m_Active)
                {
                    string errorMessage = "Socket is not active.";
                    if (NetworkChannelError != null)
                    {
                        NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);
                        return;
                    }

                    throw new GameFrameworkException(errorMessage);
                }

                if (packet == null)
                {
                    string errorMessage = "Packet is invalid.";
                    if (NetworkChannelError != null)
                    {
                        NetworkChannelError(this, NetworkErrorCode.SendError, SocketError.Success, errorMessage);
                        return;
                    }

                    throw new GameFrameworkException(errorMessage);
                }

                lock (m_SendPacketPool)
                {
                    m_SendPacketPool.Enqueue(packet);
                }

View on GitHub (pinned to d0c010b051)