Exemplo n.º 1
0
        public override async Task OnConnected(WebSocket socket)
        {
            await base.OnConnected(socket);

            var socketId = WebSocketConnectionManager.GetId(socket);

            await SendMessageToAllAsync($"{socketId} is now connected");
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
            }
        }