Connection

Overview

The first thing a client starts to do is to establish a connection to the server of Realtime Engine.

Specifically, this connection typically uses WebSocket, but XHR Polling will be used instead in special cases, for example, in browsers of old versions.

We guarantee that Connection is available and stable in most network environments as well as on clients.

Establish Connection

In client SDK, after instantializing the Engine object, the connection will be automatically established, and a reconnection will be made in the case that network is unstable.

For more details, please refer to the corresponding SDK documentation.

Terminate Connection

Typicall the Engine object has the disconnect method, which can be used to terminate a connection initiatively.

For more details, please refer to the corresponding SDK documentation.

Connection Stata

While using client SDK, you can monitor the connection state to present friendly prompts to users when necessary.

Possible States

  • initialized: The initial state, a connection has not yet been initiated.
  • connecting: Is connecting. When a reconnection is made automatically, the connection will also enter this state. Binding the connecting_in Event can get how soon the connection will be attempted to made next time.
  • connected: A connection has been made.
  • failed: A connection failed to be made, which is due to browser incompatibility, client SDK configuration error or out of date. Binding the error Event can get the detailed error information.
  • disconnected: A connection was made previously, but now has been disconnected initiatively.

State Transition Examples

When everything goes exactly right:

initialized -> connecting -> connected

When the network is unstable or disconnected:

connected -> connecting

When the network is restored:

connecting -> connected

When a connection is not able to be made:

initialized -> failed

Monitor

Through the following two ways:

  • Directly access the state attribute of the Connection object on Engine.
  • Bind the state_changed Event on Connection .

For more details, please refer to the corresponding SDK documentation.

  Back To Top