public async Task ReceiveMessagesUntilCloseAsync() { byte[] receivePayloadBuffer = new byte[_receivePayloadBufferSize]; WebSocketReceiveResult webSocketReceiveResult = await _webSocket.ReceiveAsync(new ArraySegment <byte>(receivePayloadBuffer), CancellationToken.None); while (webSocketReceiveResult.MessageType != WebSocketMessageType.Close) { if (webSocketReceiveResult.MessageType == WebSocketMessageType.Binary) { byte[] webSocketMessage = await ReceiveMessagePayloadAsync(_webSocket, webSocketReceiveResult, receivePayloadBuffer); ReceiveBinary?.Invoke(this, webSocketMessage); } else { byte[] webSocketMessage = await ReceiveMessagePayloadAsync(_webSocket, webSocketReceiveResult, receivePayloadBuffer); ReceiveText?.Invoke(this, Encoding.UTF8.GetString(webSocketMessage)); } webSocketReceiveResult = await _webSocket.ReceiveAsync(new ArraySegment <byte>(receivePayloadBuffer), CancellationToken.None); } CloseStatus = webSocketReceiveResult.CloseStatus.Value; CloseStatusDescription = webSocketReceiveResult.CloseStatusDescription; }
internal ReceiveTextEvent InvokeEvent(ReceiveTextEvent arg) { if (_api.ValidateEvent(arg)) { ReceiveText?.Invoke(_api, arg); } return(arg); }
private void OnReceiveText(string webSocketMessage) { ReceiveText?.Invoke(this, webSocketMessage); }
private void OnReceiveText(string webSocketMessage) { string message = _textSubProtocol.Read(webSocketMessage); ReceiveText?.Invoke(this, message); }
private void OnReceiveText(string socketMessage) { var message = _textSubProtocol.Read(socketMessage); ReceiveText?.Invoke(this, message); }