Skip to main content
Version: v3

INetTips

Important Attention Reminder

Coding Style wiki​


INetTips is the connection status notification interface of NetFrame. Whenever a node's connection state changes (connecting, connected, error, disconnected, reconnecting), the NetNode automatically invokes the corresponding interface method — ideal for implementing connection loading masks, error dialogs, and reconnection prompts.

NamespaceOxGFrame.NetFrame
Typepublic interface
SourceINetTips.cs
using OxGFrame.NetFrame;

Declaration

public interface INetTips

Status & Trigger Timing​

NetNode manages the connection state internally with the NetStatus enum; each state transition triggers the corresponding INetTips method:

NetStatusMethodTrigger Timing
CONNECTINGOnConnectingWhen Connect starts the connection procedure.
CONNECTEDOnConnectedWhen the connection is successfully established.
CONNECTION_ERROROnConnectionErrorWhen a communication error occurs.
DISCONNECTEDOnDisconnectedWhen the connection is closed or lost.
RECONNECTINGOnReconnectingWhen the node enters the auto-reconnection procedure after a disconnection.

Reminder Pass an implementation instance when creating the NetNode (new NetNode(provider, netTips)), or assign it later via NetNode.SetNetTips.

Member Overview​

MethodDescription
OnConnectingTriggered when the connection procedure starts.
OnConnectedTriggered when the connection is successfully established.
OnConnectionErrorTriggered when a communication error occurs.
OnDisconnectedTriggered when the connection is closed or lost.
OnReconnectingTriggered when the auto-reconnection procedure starts.

OnConnecting​

void OnConnecting()

Description

Triggered when NetFrames.Connect (or NetNode.Connect) starts the connection procedure. Typically used to open a "connecting" UI mask to prevent duplicate operations.


OnConnected​

void OnConnected(object payload)

Parameters

ParameterTypeDescription
payloadobjectInformation about the established connection. The content depends on the provider (built-in TcpNetProvider / KcpNetProvider pass 0; WebSocketNetProvider passes the open event args).

Description

Triggered when the connection is successfully established. Typically used to close the connecting mask and continue with follow-up logic such as login or data synchronization.


OnConnectionError​

void OnConnectionError(object payload)

Parameters

ParameterTypeDescription
payloadobjectError information (all built-in implementations pass an error message string).

Description

Triggered when a communication error occurs. Typically used to show an error dialog prompting the user to check the network environment.


OnDisconnected​

void OnDisconnected(object payload)

Parameters

ParameterTypeDescription
payloadobjectDisconnection information (built-in TcpNetProvider / KcpNetProvider pass -1; WebSocketNetProvider passes the close code; null when transitioning to disconnected after auto-reconnection ends).

Description

Triggered when the connection is closed or lost (whether manually or unexpectedly). Typically used for data cleanup or returning to the login screen.


OnReconnecting​

void OnReconnecting()

Description

Triggered when the connection is lost without a manual close and the node enters the auto-reconnection procedure. Typically used to show a "network unstable, reconnecting..." prompt.

Attention
  • Auto-reconnection is controlled by NetOption.autoReconnectCount; once the attempts are exhausted, the state transitions to OnDisconnected.
  • Closing the connection manually via NetFrames.Close (or NetNode.Close) never triggers auto-reconnection.

Implementation Example​

Define a class implementing INetTips and attach it to a NetNode:

using OxGFrame.NetFrame;
using UnityEngine;

public class NetTipsExample : INetTips
{
public void OnConnecting()
{
// Open the "connecting" mask to prevent duplicate operations
Debug.Log("Connecting...");
}

public void OnConnected(object payload)
{
// Close the mask and continue with login or data synchronization
Debug.Log($"Connected: {payload}");
}

public void OnConnectionError(object payload)
{
// Show a connection error prompt
Debug.LogError($"Connection error: {payload}");
}

public void OnDisconnected(object payload)
{
// Clean up data or return to the login screen
Debug.LogWarning($"Disconnected: {payload}");
}

public void OnReconnecting()
{
// Show the "reconnecting" prompt UI
Debug.Log("Attempting to reconnect...");
}
}
// Pass it in when creating the node
var netNode = new NetNode(new TcpNetProvider(), new NetTipsExample());

// Or assign it on an existing node
netNode.SetNetTips(new NetTipsExample());

Attention The actual content of payload depends on the underlying provider — perform a type check before using it.