ISocketServer

The ISocketServer interface provides the core functionalities of a socket server, which is created using the SocketBuilder class. This interface allows starting, stopping the server, and sending messages to clients. After being configured through the SocketBuilder, the ISocketServer can receive messages from clients, perform certain operations, and send messages back to clients. The server can operate based on either TCP or UDP protocols.


Configured with SocketBuilder: ISocketServer can only be created using the SocketBuilder class. The SocketBuilder takes server configuration settings (e.g., connection settings, message processing configurations) and creates an appropriate server instance.


Operations Possible with ISocketServer:

  • Managing Client Connections: The server accepts incoming client connections and communicates with each connected client.

  • Sending and Receiving Messages: The server can send messages to a specific client and receive messages from clients.


Additional Properties and Events:

  • Enabled Property:

    This property returns a bool indicating whether the server is enabled and currently running. It can be used to check if the server is active or stopped.

if (socketServer.Enabled)
{
    // Proceed with operations
}
  • OnMessageReceived Event:

    This event is triggered when a message is received from a connected client. The event handler receives the EndPoint (representing the client’s address) and the message string.

socketServer.OnMessageReceived += (endPoint, message) =>
{
    Console.WriteLine($"Message from {endPoint}: {message}");
};

Operations:

The ISocketServer interface provides all the fundamental functions needed for the socket server to operate efficiently. These functionalities can only work optimally when used with correct configurations (such as SocketConfig, MessageConfig, etc.).

Last updated