Open chachew opened 4 years ago
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."); }
Hi @chachew! webSocket has IsConnected property. And null message is received on remote party disconnect.
webSocket
IsConnected
null
Thanks, i ended up figuring that out after some messing around with it.
How do i know when a client closes its socket connection?