using libstrophe, can I reconnect automatically when I loose connection. I used the following code on the client side:
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
const int error, xmpp_stream_error_t * const stream_error,
void * const userdata)
{
if (status == XMPP_CONN_CONNECT) {
fprintf(stderr, "DEBUG: connected\n");
}
else {
fprintf(stderr, "DEBUG: disconnected\n");
}
}
void main()
{
xmpp_log_t *log;
char *jid;
jid = strdup("[email protected]")
xmpp_initialize();
log = xmpp_get_default_logger(XMPP_LEVEL_ERROR);
cwmp->xmpp_ctx = xmpp_ctx_new(NULL, log);
cwmp->xmpp_conn = xmpp_conn_new(cwmp->xmpp_ctx);
xmpp_conn_set_jid(cwmp->xmpp_conn, jid);
xmpp_conn_set_pass(cwmp->xmpp_conn, cwmp->xmpp_param.password);
xmpp_connect_client(cwmp->xmpp_conn, NULL, 0, conn_handler, cwmp->xmpp_ctx);
xmpp_run(cwmp->xmpp_ctx);
}
when the client is connected for the first time, i get the message "DEBUG: connected" When the server goes done, i get the message "DEBUG: disconnected". but when the server is up for the second time, the client is not reconnected automatically.
Libstrophe doesn't reconnect automatically. Starting from libstrophe-0.9.0
xmpp_conn_t
object can be reconnected without loosing login information and user handlers:In versions before 0.9.0 user can't reuse
xmpp_conn_t
object after disconnection and needs to create new one. Example for libstrophe-0.8.8 and older: