Table of Contents

Class MoongateTCPServer

Namespace
Moongate.Network.Server
Assembly
Moongate.Network.dll

High-throughput TCP server with client lifecycle events and middleware-enabled payload dispatch.

public sealed class MoongateTCPServer : IAsyncDisposable, IDisposable
Inheritance
MoongateTCPServer
Implements
Inherited Members

Constructors

MoongateTCPServer(IPEndPoint, int, int)

Initializes a TCP server bound to the given endpoint.

public MoongateTCPServer(IPEndPoint endPoint, int receiveBufferSize = 8192, int historyBufferCapacity = 65536)

Parameters

endPoint IPEndPoint

Endpoint to bind to. Use port 0 for dynamic port assignment.

receiveBufferSize int

Per-client receive buffer size.

historyBufferCapacity int

Per-client circular history capacity.

Properties

Port

Current listening port.

public int Port { get; }

Property Value

int

Methods

AddMiddleware(INetMiddleware)

Registers middleware in execution order.

public MoongateTCPServer AddMiddleware(INetMiddleware middleware)

Parameters

middleware INetMiddleware

Returns

MoongateTCPServer

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

StartAsync(CancellationToken)

Starts accepting clients.

public Task StartAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

StopAsync(CancellationToken)

Stops accepting new clients and closes all active clients.

public Task StopAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

Events

OnClientConnect

Raised when a client connects.

public event EventHandler<MoongateTCPClientEventArgs>? OnClientConnect

Event Type

EventHandler<MoongateTCPClientEventArgs>

OnClientDisconnect

Raised when a client disconnects.

public event EventHandler<MoongateTCPClientEventArgs>? OnClientDisconnect

Event Type

EventHandler<MoongateTCPClientEventArgs>

OnDataReceived

Raised when a client sends data after middleware processing.

public event EventHandler<MoongateTCPDataReceivedEventArgs>? OnDataReceived

Event Type

EventHandler<MoongateTCPDataReceivedEventArgs>

OnException

Raised when an exception happens in accept loop or client loops.

public event EventHandler<MoongateTCPExceptionEventArgs>? OnException

Event Type

EventHandler<MoongateTCPExceptionEventArgs>