forked from vtortola/WebSocketListener
-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
How do i know when a client closes its socket connection?
public async Task AcceptWebSocketsAsync(WebSocketListener server, CancellationToken cancellation)
{
await Task.Yield();
while (!cancellation.IsCancellationRequested)
{
try
{
var webSocket = await server.AcceptWebSocketAsync(cancellation).ConfigureAwait(false);
if (webSocket == null)
{
if (cancellation.IsCancellationRequested || !server.IsStarted) break; // stopped
continue; // retry
}
await WebSocketHandler.OnConnected(webSocket, 123);
#pragma warning disable 4014
EchoAllIncomingMessagesAsync(webSocket, cancellation);
#pragma warning restore 4014
}
catch (OperationCanceledException)
{
/* server is stopped */
break;
}
catch (Exception)
{
//Log.Error("An error occurred while accepting client.", acceptError);
}
}
//Log.Warning("Server has stopped accepting new clients.");
}
Metadata
Metadata
Assignees
Labels
No labels