Skip to content

Reconnection

Daniel Rhodes edited this page Mar 3, 2016 · 3 revisions

Reconnection Strategies

In some scenarios you will want to manipulate the client's approach to reconnecting with the server if the connection flaps.

Several options are available:

  1. Exponential Backoff
self.client.reconnectionStrategy = .ExponentialBackoff(maxRetries: 30, maxIntervalTime: 10)
  1. Logarithmic Backoff
self.client.reconnectionStrategy = .LogarithmicBackoff(maxRetries: 30, maxIntervalTime: 10)
  1. Linear
self.client.reconnectionStrategy = .Linear(maxRetries: 30, maxIntervalTime: 10)
  1. None
self.client.reconnectionStrategy = .None

maxIntervalTime in this case is the maximum time interval between requests.

Reconnect Handler

If you have defined a reconnectionStrategy, then you can also be notified when a reconnection is about to occur and cancel this attempt, as shown below:

self.client.willReconnect = {

  if (someConditionToNotReconnect) {
     return false 
  }

  return true
}
Clone this wiki locally