From b8b2c4a7c82f722513a235f5f7ef77dfe38691a3 Mon Sep 17 00:00:00 2001 From: uwaa Date: Fri, 15 Nov 2024 15:22:00 +0000 Subject: [PATCH] add websocket timeouts --- HTTP.Example/Program.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/HTTP.Example/Program.cs b/HTTP.Example/Program.cs index 2416ff4..7e79017 100644 --- a/HTTP.Example/Program.cs +++ b/HTTP.Example/Program.cs @@ -104,12 +104,13 @@ static class Program static async Task HandleWebsocket(Websocket ws) { - DataFrame payload = await ws.Read(); + TimeSpan timeout = TimeSpan.FromMinutes(1); + DataFrame payload = await ws.Read().WaitAsync(timeout); if (payload.Opcode != WSOpcode.Close) { string result = payload.AsString(); - await ws.Write($"Echoing message: \"{result}\""); + await ws.Write($"Echoing message: \"{result}\"").WaitAsync(timeout); } return CloseStatus.NormalClosure;