ConnectToServer

This method connects the client to the WebSocket server using the URI specified in the serverUri variable.

What it does: Attempts to connect to the WebSocket server. If successful, it starts receiving messages from the server asynchronously.

How to use it: Call this method to initiate the WebSocket connection.

Usage:

await ChatClient.ConnectToServer();

Example:

try
{
    await ChatClient.ConnectToServer();
    Console.WriteLine("Connected to server.");
}
catch (Exception ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}

Last updated