/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> public Task SendAsync(byte[] bytes, Model.Net.WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) { WebSocketMessageType nativeType; if (!Enum.TryParse(type.ToString(), true, out nativeType)) { _logger.Warn("Unrecognized WebSocketMessageType: {0}", type.ToString()); } return(_client.SendAsync(new ArraySegment <byte>(bytes), nativeType, true, cancellationToken)); }
/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="onError"></param> public void Send(byte[] bytes, Model.Net.WebSocketMessageType type, bool endOfMessage, Action <Exception> onError) { ThreadPool.QueueUserWorkItem((socket) => { try { _socket.Send(bytes, 0, bytes.Length); } catch (Exception e) { onError(e); } }); }
/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> public async Task SendAsync(byte[] bytes, Model.Net.WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken) { await _sendResource.WaitAsync(cancellationToken).ConfigureAwait(false); try { WebSocketMessageType nativeType; if (!Enum.TryParse(type.ToString(), true, out nativeType)) { _logger.Warn("Unrecognized WebSocketMessageType: {0}", type.ToString()); } await _client.SendAsync(new ArraySegment <byte>(bytes), nativeType, true, cancellationToken).ConfigureAwait(false); } finally { _sendResource.Release(); } }
/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> public void Send(byte[] bytes, Model.Net.WebSocketMessageType type, bool endOfMessage) { _socket.Send(bytes, 0, bytes.Length); }
/// <summary> /// Sends the async. /// </summary> /// <param name="bytes">The bytes.</param> /// <param name="type">The type.</param> /// <param name="endOfMessage">if set to <c>true</c> [end of message].</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>Task.</returns> public Task SendAsync(byte[] bytes, Model.Net.WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken = default(CancellationToken)) { return(Task.Run(() => _socket.Send(bytes, 0, bytes.Length), cancellationToken)); }