Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow async ping #539

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions websocket-sharp/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,16 @@ private bool ping (byte[] data)
}
}

private void pingAsync (byte[] data, Action<bool> 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;
Expand Down Expand Up @@ -3304,6 +3314,18 @@ public bool Ping ()
return ping (EmptyBytes);
}

/// <summary>
/// Sends a ping using the WebSocket connection.
/// </summary>
/// <returns>
/// <c>true</c> if the send has done with no error and a pong has been
/// received within a time; otherwise, <c>false</c>.
/// </returns>
public void PingAsync (Action<bool> completed)
{
pingAsync (EmptyBytes, completed);
}

/// <summary>
/// Sends a ping with <paramref name="message"/> using the WebSocket
/// connection.
Expand Down