8 years, 11 months ago.

how to reconnect to websocket server

Hi all, I am developing the IOT app. where websocket client is running on the mbed. I have deployed the websocket server on java (as mbed websocket server has been shutdown).

I need to ask how can I reconnect my websocket mbed client to java server if some one shutdowns websocket server for a while and opened it again. I have observed that if I try to reconnect it, the client get stuck adn nothing happens following is the chunk of my code:

Websocket ws(url)

int main()
{
if (ws.connected())
{
ws.send("i am alive \n")
}
if (!ws.connected())
{
printf("reconnecing");
ws.connect();
}

}

The code get stuck at reconnecting and it do nothing. Can any one know how to check that websocket is gone down and try to reconnect it.

Be the first to answer this question.