Exemplo n.º 1
0
        private void ChatRoomHandler_OnConnected(HttpContext context, System.Net.WebSockets.WebSocket socket)
        {
            var id = Guid.NewGuid().ToString();

            webSocketInstances.Add(id, socket);
            Parallel.ForEach(webSocketInstances.Values.Where(x => x != socket), x => {
                //未確認訊息情況下直接廣播
                x.SendTextAsync("使用者: " + id + " 登入").GetAwaiter().GetResult();
            });
            socket.SendTextAsync("使用者: " + id + " 歡迎").GetAwaiter().GetResult();
        }