diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 93ed5bf4e..57912b728 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -1578,6 +1578,16 @@ private bool ping (byte[] data) } } + private void pingAsync (byte[] data, Action completed) + { + if (_readyState != WebSocketState.Open) { + var msg = "The current state of the connection is not Open."; + throw new InvalidOperationException (msg); + } + + sendAsync (Opcode.Ping, new MemoryStream (data), completed); + } + private bool processCloseFrame (WebSocketFrame frame) { var payload = frame.PayloadData; @@ -3304,6 +3314,18 @@ public bool Ping () return ping (EmptyBytes); } + /// + /// Sends a ping using the WebSocket connection. + /// + /// + /// true if the send has done with no error and a pong has been + /// received within a time; otherwise, false. + /// + public void PingAsync (Action completed) + { + pingAsync (EmptyBytes, completed); + } + /// /// Sends a ping with using the WebSocket /// connection.