public override async Task OnConnected(WebSocket socket) { await base.OnConnected(socket); var socketId = WebSocketConnectionManager.GetId(socket); await SendMessageToAllAsync($"{socketId} is now connected"); }
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); }
public WebSocketHandler(WebSocketConnectionManager webSocketConnectionManager) { WebSocketConnectionManager = webSocketConnectionManager; }
public ChatMessageHandler(WebSocketConnectionManager webSocketConnectionManager) : base(webSocketConnectionManager) { }