BuildServer
Description: This method builds and returns a socket server instance based on the configurations provided. The server can handle incoming client connections and process messages according to the defined message settings.
Returns:
ISocketServer
: Returns the created socket server instance.If there is a missing or invalid configuration (e.g.,
SocketConfig
,MessageConfig
, orClientValidationConfig
), this method returnsnull
.
The BuildServer
method is responsible for creating and configuring a socket server instance. It first checks if the necessary configurations (SocketConfig
, MessageConfig
, and ClientValidationConfig
) have been correctly provided.
Once the configurations are verified, the method constructs a server based on the selected socket protocol (either TCP or UDP). It then creates an appropriate message service, which could be either a compressed or default message processor based on the settings in MessageConfig
. The server will be able to process and manage incoming connections and data transmission, depending on the chosen protocol and message settings.
TCP Server: If the protocol is TCP, a server that can handle multiple client connections is created, and the message service is initialized for TCP.
UDP Server: If the protocol is UDP, the method builds a server capable of managing datagram-based communication, without the need for the connection management found in TCP.
If the server is successfully created, an instance of ISocketServer
is returned, which can be used to accept client connections and handle data transmission.
Important Notes:
Client Validation: For TCP servers, client validation is performed using the provided
ClientValidationConfig
, which can include IP whitelists and blacklists, as well as authentication keys. However, for UDP servers, client validation is not required, so theClientValidationConfig
is ignored.Error Handling: If any configuration is invalid, an error message will be logged, and
null
will be returned.Message Processing: The message service created here depends on the
MessageConfig
settings, allowing for either compressed or standard message handling.
Usages:
Last updated