[Libwebsockets] Accessing user data in websocket callback

Hemant Kumar hkumar at arubanetworks.com
Fri Aug 14 00:21:28 CEST 2015


Hi

I am trying to set some user data so that to access it in libwebsocket callback and using libwebsocket_client_connect_extended() to achieve this.
But after connection gets ESTABLISHED, I do not see the same data.

Code construct:

Int a =5;

Main(..)
{

  client_socket = libwebsocket_client_connect_extended(context, address, port, use_ssl,
                            "/", address, address,
                            protocols[0].name, ietf_version, (void*)&a);<<<setting value as 5.



        if (client_socket == NULL) {
                fprintf(stderr, "libwebsocket connect failed\n");
                ret = 1;
                goto bail;
        }
        lwsl_notice("connected to server..%s user data %d\n",address, *((int*)(client_socket->user_space)));>>>correctly prints 5


}


callback(...)
{
 case LWS_CALLBACK_CLIENT_ESTABLISHED:

                    lwsl_notice("data_callback_handler: LWS_CALLBACK_CLIENT_ESTABLISHED\n");

                    lwsl_notice("user data %d\n",*((int*)(client_socket->user_space)));<<<<<<<<<<<<Incorrect prints 0
                    libwebsocket_callback_on_writable(context, client_socket);


case LWS_CALLBACK_CLIENT_WRITEABLE:
                    lwsl_notice("LWS_CALLBACK_CLIENT_WRITEABLE\n");
                    lwsl_notice("user data %d\n",*((int*)(client_socket->user_space)));<<<<<<<<<<<Incorrect prints 0

}
Can someone please suggest what I am doing wrong here?

Any help will be appreciated.

Thanks
Hemant

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20150813/1469e13b/attachment.html>


More information about the Libwebsockets mailing list