NetOption
Coding Style wiki
NetOption is the abstract base class of NetFrame connection options and defines the auto-reconnection setting shared by all protocols. Three built-in derived classes carry the connection parameters of the three built-in providers; when implementing a custom provider, you can also inherit this class to add your own options.
| Namespace | OxGFrame.NetFrame |
| Type | public abstract class |
| Source | NetOption.cs |
using OxGFrame.NetFrame;
Declaration
public abstract class NetOption
Derived Class Overview
| Class | Provider | Description |
|---|---|---|
| TcpNetOption | TcpNetProvider | TCP connection options (host, port, and packet processing settings). |
| KcpNetOption | KcpNetProvider | KCP connection options (host, port, channel, and KCP config). |
| WebSocketNetOption | WebSocketNetProvider | WebSocket connection options (connection URL). |
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| autoReconnectCount | int | -1 | Number of automatic reconnection attempts. When greater than 0, the node automatically retries after an unintentional disconnection, decrementing the count per attempt; -1 disables auto-reconnection. Use int.MaxValue for practically unlimited retries. |
Constructor
public NetOption(int autoReconnectCount = -1)
Parameters
| Parameter | Type | Description |
|---|---|---|
| autoReconnectCount | int | Number of automatic reconnection attempts. Default: -1 (auto-reconnection disabled) |
Description
Called by derived-class constructors via base(autoReconnectCount) to initialize the reconnection count.
Reminder The reconnection interval and callback can be configured via NetNode.SetReconnectTickerTime (default: 5 seconds) and NetNode.SetReconnectAction.
TcpNetOption
Connection options for TcpNetProvider (Telepathy).
| Type | public class |
| Source | TcpNetOption.cs |
Declaration
public class TcpNetOption : NetOption
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| host | string | — | Server host address. |
| port | int | — | Server port. |
| processLimitPerTick | int | 64 | Maximum number of packets processed per polling tick. |
| maxBufferSize | int | 65536 | Maximum buffer size of a single packet (64KB). |
Constructors
public TcpNetOption(string host, int port, int autoReconnectCount = -1)
public TcpNetOption(string host, int port, int processLimitPerTick, int maxBufferSize = 65536, int autoReconnectCount = -1)
Parameters
| Parameter | Type | Description |
|---|---|---|
| host | string | Server host address. |
| port | int | Server port. |
| processLimitPerTick | int | Maximum number of packets processed per polling tick. |
| maxBufferSize | int | Maximum buffer size of a single packet. Default: 65536 |
| autoReconnectCount | int | Number of automatic reconnection attempts. Default: -1 (auto-reconnection disabled) |
Example
// Basic connection (auto-reconnect 3 times after disconnection)
var tcpOption = new TcpNetOption("127.0.0.1", 8888, autoReconnectCount: 3);
NetFrames.Connect(tcpOption);
// Custom per-tick processing limit and buffer size
var tunedOption = new TcpNetOption("127.0.0.1", 8888, processLimitPerTick: 128, maxBufferSize: 131072);
KcpNetOption
Connection options for KcpNetProvider (kcp2k).
| Type | public class |
| Source | KcpNetOption.cs |
Declaration
public class KcpNetOption : NetOption
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| host | string | — | Server host address. |
| port | int | — | Server port. |
| kcpChannel | KcpChannel | KcpChannel.Reliable | KCP transmission channel (Reliable / Unreliable). |
| config | KcpConfig | Built-in default config (see below) | kcp2k connection configuration (NoDelay, window sizes, timeout, etc.). |
The built-in default value of config:
new KcpConfig
(
NoDelay: true,
DualMode: false,
Interval: 1,
Timeout: 2000,
SendWindowSize: Kcp.WND_SND * 1000,
ReceiveWindowSize: Kcp.WND_RCV * 1000,
CongestionWindow: false,
MaxRetransmits: Kcp.DEADLINK * 2
)
Constructors
public KcpNetOption(string host, int port, KcpChannel kcpChannel = KcpChannel.Reliable, int autoReconnectCount = -1)
public KcpNetOption(string host, int port, KcpConfig config, KcpChannel kcpChannel = KcpChannel.Reliable, int autoReconnectCount = -1)
Parameters
| Parameter | Type | Description |
|---|---|---|
| host | string | Server host address. |
| port | int | Server port. Cast to ushort (0–65535) when connecting. |
| config | KcpConfig | Custom kcp2k connection configuration. If omitted, the built-in default config is used. |
| kcpChannel | KcpChannel | KCP transmission channel. Default: KcpChannel.Reliable |
| autoReconnectCount | int | Number of automatic reconnection attempts. Default: -1 (auto-reconnection disabled) |
Example
using kcp2k;
// Use the built-in default config
var kcpOption = new KcpNetOption("127.0.0.1", 7777);
NetFrames.Connect(kcpOption);
// Custom KcpConfig
var config = new KcpConfig(NoDelay: true, Interval: 10, Timeout: 5000);
var customOption = new KcpNetOption("127.0.0.1", 7777, config, KcpChannel.Reliable, autoReconnectCount: 3);
WebSocketNetOption
Connection options for WebSocketNetProvider (UnityWebSocket).
| Type | public class |
| Source | WebSocketNetOption.cs |
Declaration
public class WebSocketNetOption : NetOption
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| url | string | — | WebSocket connection URL (ws:// or wss://). |
Constructor
public WebSocketNetOption(string url, int autoReconnectCount = -1)
Parameters
| Parameter | Type | Description |
|---|---|---|
| url | string | WebSocket connection URL (ws:// or wss://). |
| autoReconnectCount | int | Number of automatic reconnection attempts. Default: -1 (auto-reconnection disabled) |
Example
var wsOption = new WebSocketNetOption("ws://127.0.0.1:8080/ws", autoReconnectCount: 3);
NetFrames.Connect(wsOption);
Custom Extension
When implementing a custom provider, inherit NetOption to add protocol-specific connection parameters:
public class CustomNetOption : NetOption
{
public string host { get; set; }
public int port { get; set; }
public CustomNetOption(string host, int port, int autoReconnectCount = -1) : base(autoReconnectCount)
{
this.host = host;
this.port = port;
}
}
Inside your provider's CreateConnect, cast the NetOption back to CustomNetOption to read the parameters (see the INetProvider implementation example).