Ejemplo n.º 1
0
        private async Task Run()
        {
            var hc = await listener.GetContextAsync();

            if (hc.Request.IsWebSocketRequest)
            {
                //WebSocketでレスポンスを返却
                var wsc = await hc.AcceptWebSocketAsync(null);

                var myws = new ws_clients(wsc.WebSocket);
                ws.Add(myws);
                var new_arg = new NewClientArg();
                new_arg.ws = myws;
                NewClient?.Invoke(this, new_arg);

                List <int> delWS = ws.Select((value, index) => new { x = value, i = index }).Where(y => (y.x.ws.State == WebSocketState.Closed) || (y.x.ws.State == WebSocketState.Aborted)).Select(x => x.i).ToList();
                delWS.ForEach(x =>
                {
                    ws.RemoveAt(x);
                });
            }
            else
            {
                WebResponse(hc);
                hc.Response.Close();
                return;
            }
        }
Ejemplo n.º 2
0
 void new_client(object sender, EventArgs ev)
 {
     if (ev is NewClientArg)
     {
         NewClientArg client = ev as NewClientArg;
         client.ws.ReceiveMessage += receive;
     }
 }