Beispiel #1
0
        public override async Task OnConnected(WebSocket socket)
        {
            await base.OnConnected(socket);

            var socketId = WebSocketConnectionManager.GetId(socket);

            await SendMessageToAllAsync($"{socketId} is now connected");
        }
Beispiel #2
0
        public override async Task OnDisconnected(WebSocket socket)
        {
            await WebSocketConnectionManager.RemoveSocket(WebSocketConnectionManager.GetId(socket));

            var dictionary = WebSocketConnectionManager.GetAll();

            if (dictionary.Count == 0)
            {
                timer.Dispose();
            }
        }
Beispiel #3
0
        public override async Task OnConnected(WebSocket socket)
        {
            await base.OnConnected(socket);

            var socketId = WebSocketConnectionManager.GetId(socket);

            var dictionary = WebSocketConnectionManager.GetAll();

            if (dictionary.Count == 1)
            {
                var autoEvent = new AutoResetEvent(false);
                timer = new Timer(SendValueAsync, autoEvent, 0, 1000);
            }
        }