/// <summary> /// Send pong message to all available clients synchronous, can have message. /// </summary> /// <param name="messageToSend">Possible extra message to send along ping.</param> /// <param name="clientId">Set clientId in case you want to send to a specific client.</param> /// <returns>True when succesfully send.</returns> public bool SendPongMessage(string messageToSend = "", string clientId = null) { WebSocketMessageContainer message = new WebSocketMessageContainer() { data = Encoding.UTF8.GetBytes(messageToSend), isPong = true }; if (clientId != null) { return(Task.Run(async() => await _WebsocketHandler.SendMessage(message, clientId)).GetAwaiter().GetResult()); } return(Task.Run(async() => await _WebsocketHandler.SendMessage(message)).GetAwaiter().GetResult()); }
/// <summary> /// Send pong message to all available clients asynchronous, can have message. /// </summary> /// <param name="messageToSend">Possible extra message to send along ping.</param> /// <param name="clientId">Set clientId in case you want to send to a specific client.</param> /// <returns>True when succesfully send.</returns> public async Task <bool> SendPongMessageAsync(string messageToSend = "", string clientId = null) { WebSocketMessageContainer message = new WebSocketMessageContainer() { data = Encoding.UTF8.GetBytes(messageToSend), isPong = true }; if (clientId != null) { return(await _WebsocketHandler.SendMessage(message, clientId)); } return(await _WebsocketHandler.SendMessage(message)); }
/// <summary> /// Sends a binary "message" to a specific client synchronous. /// </summary> /// <param name="messageToSend">Message in binary format (byte array).</param> /// <param name="clientId">Client to send to.</param> /// <returns>True when succesfully send.</returns> public bool SendBinaryMessage(byte[] messageToSend, string clientId = null) { WebSocketMessageContainer message = new WebSocketMessageContainer() { data = messageToSend, isBinary = true }; if (clientId != null) { return(Task.Run(async() => await _WebsocketHandler.SendMessage(message, clientId)).GetAwaiter().GetResult()); } return(Task.Run(async() => await _WebsocketHandler.SendMessage(message)).GetAwaiter().GetResult()); }
/// <summary> /// Sends a binary "message" to a specific client asynchronous. /// </summary> /// <param name="messageToSend">Message in binary format (byte array).</param> /// <param name="clientId">Client to send to.</param> /// <returns>True when succesfully send.</returns> public async Task <bool> SendBinaryMessageAsync(byte[] messageToSend, string clientId = null) { WebSocketMessageContainer message = new WebSocketMessageContainer() { data = messageToSend, isBinary = true }; if (clientId != null) { return(await _WebsocketHandler.SendMessage(message, clientId)); } return(await _WebsocketHandler.SendMessage(message)); }