Interface ISynchronousServer
Provides methods for implementing a synchronous server that handles incoming client connections.
Members
Method HandleClient
Processes a single incoming client connection synchronously.
This method is called for each new client connection. It should contain the logic for reading from and writing to the client socket, processing requests, and sending responses. The method is expected to complete before the next client connection can be handled.
If the cancellationToken
is signaled, the method should gracefully stop processing the current client and return.
Parameters
client
: The TcpClient object representing the connected client.cancellationToken
: A CancellationToken that can be used to signal cancellation requests.
Remarks
Implementations of this method are responsible for managing the client's session, including data exchange and error handling. It's crucial to ensure that operations within this method are non-blocking or are handled in a way that doesn't indefinitely stall the server if the client is unresponsive, especially when considering the synchronous nature.
For more complex scenarios or when dealing with a high volume of connections, consider using asynchronous patterns or offloading processing to separate threads to avoid blocking the main server loop.