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

            var socketId = WebSocketConnectionManager.GetId(socket);

            await SendMessageToAllAsync($"{socketId} is now connected");
        }
示例#2
0
        public override async Task ReceiveAsync(WebSocket socket, WebSocketReceiveResult result, byte[] buffer)
        {
            var socketId       = WebSocketConnectionManager.GetId(socket);
            var message        = $"{socketId} said: {Encoding.UTF8.GetString(buffer, 0, result.Count)}";
            var decodedMessage = Encoding.UTF8.GetString(buffer, 0, result.Count);

            if (decodedMessage.StartsWith("SN:"))
            {
                var isSucced = WebSocketConnectionManager.ChangeSNForWebSocket(socketId, decodedMessage.Split(':')[1]);
            }

            await SendMessageToAllAsync(message);
        }
示例#3
0
 public WebSocketHandler(WebSocketConnectionManager webSocketConnectionManager)
 {
     WebSocketConnectionManager = webSocketConnectionManager;
 }
示例#4
0
 public ChatMessageHandler(WebSocketConnectionManager webSocketConnectionManager) : base(webSocketConnectionManager)
 {
 }