INetTips
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.
| Namespace | OxGFrame.NetFrame |
| Type | public interface |
| Source | INetTips.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:
| NetStatus | Method | Trigger Timing |
|---|---|---|
CONNECTING | OnConnecting | When Connect starts the connection procedure. |
CONNECTED | OnConnected | When the connection is successfully established. |
CONNECTION_ERROR | OnConnectionError | When a communication error occurs. |
DISCONNECTED | OnDisconnected | When the connection is closed or lost. |
RECONNECTING | OnReconnecting | When 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
| Method | Description |
|---|---|
| OnConnecting | Triggered when the connection procedure starts. |
| OnConnected | Triggered when the connection is successfully established. |
| OnConnectionError | Triggered when a communication error occurs. |
| OnDisconnected | Triggered when the connection is closed or lost. |
| OnReconnecting | Triggered 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
| Parameter | Type | Description |
|---|---|---|
| payload | object | Information 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
| Parameter | Type | Description |
|---|---|---|
| payload | object | Error 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
| Parameter | Type | Description |
|---|---|---|
| payload | object | Disconnection 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(orNetNode.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.