Troubleshooting Edge SDK Applications > WebSocket Disconnects
WebSocket Disconnects
WebSocket disconnects can happen by choice, or due to exceptional/error conditions. Here is some information about what happens in each case:
Clean disconnect: During a clean disconnect, the user or application will initiate a disconnect sequence. This sequence has two steps. First, if one or more things are bound to the WebSocket, the client will send an UNBIND message to the ThingWorx platform. This message will cause things that are bound to the websocket to appear as offline (their isConnected property will be set to false). Then, the client will close the WebSocket according to the WebSocket protocol.
Exceptions/Errors: In many cases, the underlying network interface will be aware of unexpected disconnects. For example, if you forcefully kill a WS EMS, the network interface of the ThingWorx platform will be notified, the WebSocket will be closed, and things will be cleanly unbound. In those cases, the updating of the isConnected property will occur very quickly. In some cases, however, the client or the server may not be aware that the network connection has become stale. For example, if a network cable is unplugged, a network interface is shut down, or an intermediate component in the connection (such as a proxy server) becomes disconnected. In those cases the platform will not become aware of the disconnected state of a device until a timeout occurs.
By default, the WS EMS and Edge SDKs periodically send a WebSocket ping to the platform, and the platform responds with a pong. The platform tracks when the last ping was received for each client. By default, if a ping has not been received in 60 seconds, and the connection has been otherwise inactive, the platform will close the WebSocket. This timeout is configurable in the WS Communication Subsystem configuration, Idle Connection Timeout (sec) parameter. Similarly, if the WS EMS does not receive a pong within a certain amount of time after sending a ping, it will close the WebSocket and begin attempting to reconnect. For the WS EMS, this ping/pong timeout can be set using ws_connection.pingpong_timeout and is set in milliseconds.
Was this helpful?