using Tesses.WebServer; using Tesses.WebServer.WebSocket; List> sendTo=new List>(); MountableServer svr=new MountableServer(new StaticServer("www")); RouteServer rsvr=new RouteServer(); svr.Mount("/api/",rsvr); rsvr.Add("/socket",async(ctx)=>{ Func? f=null; await ctx.StartWebSocketConnectionAsync(async(sendMessage,ping,token)=>{ f=sendMessage; await sendMessage(WebSocketMessage.Create("Hello")); lock(sendTo){ sendTo.Add(sendMessage); } while(!token.IsCancellationRequested) { await Task.Delay(100); } },async(message)=>{ List> sendTo2=new List>(); lock(sendTo) { sendTo2.AddRange(sendTo); } Console.WriteLine($"Message: {message.Text}"); foreach(var item in sendTo2) { await item(message); } },(clean)=>{ lock(sendTo){ if(f!= null) sendTo.Remove(f); } }); }); svr.StartServer(4449);