Added sendPing method #58

Closed
wants to merge 1 commit into
from

Projects

None yet

7 participants

@olegam

Added sendPing method to test if the connection is still working. If the ping fails the connection will fail after the timeoutInterval specified in the initial NSURLRequest.

Ole Gammelgaard Poulsen Added sendPing method to test if the connection is still working. If …
…the ping fails the connection will fail after the timeoutInterval specified in the initial NSURLRequest.
e19ead9
@mikelikespie

I agree adding ping would be useful, but I think it will be more useful in another form.

In the context of a heartbeat, timeout, or have a callback with the response time.

If adding a heartbeat, one should be able to set the timeout, and optionally add a delegate method for the pongs that yields the current latency.

@aidansteele aidansteele commented on the diff Dec 3, 2012
SocketRocket/SRWebSocket.m
@@ -631,6 +631,13 @@ - (void)send:(id)data;
});
}
+- (void)sendPing {
+ NSAssert(self.readyState != SR_CONNECTING, @"Invalid State: Cannot call send: until connection is open");
@aidansteele
aidansteele Dec 3, 2012

Wouldn't this assertion (erroneously) pass if the state is closing or closed?

@l4u
l4u commented Feb 6, 2013

@aidansteele
The same assert apperas in - (void)send:(id)data as well.

👍 for adding heartbeat.

@cbrauchli cbrauchli added a commit to cbrauchli/SocketRocket that referenced this pull request Jul 10, 2014
@cbrauchli cbrauchli Add ability to specify a heartbeat interval and timeout
Similar to #58 (and others), this lets the client add ping/pong logic to their connection to check that it's open. However, rather than exposing a `-sendPing` method, this abstracts it away into the concept of a "heartbeat."

I added two properties:
 - `heartbeatInterval`: specifies how long (in seconds) to wait after no messages have been sent/received before sending a _ping_ message. Defaults to zero, which means no heartbeat, since
  -`heartbeatTimeout`: specifies how long to wait after sending a _ping_ frame for any message to arrive. If the response takes too long, disconnects.

If this is approved, I'm happy to add another (optional) delegate method `- (void)webSocket:heartbeatWasAcknowledgedAfter:(NTTimeInterval)roundTripTimeInSeconds`. Also, maybe adding a specific close code for connections closed by a heartbeat timeout would be a good idea (for use in the `webSocket:didCloseWithCode:...` delegate method).
2a3a941
@dfed

Doing some housecleaning. If this is still an issue please fix conflicts and reopen. We'll do a better job of reviewing quickly this time, I promise.

@dfed dfed closed this Sep 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment