[Libwebsockets] confused regarding multiple protocols

Dorian Green doriangreen97 at gmail.com
Sat Jun 6 00:46:32 CEST 2020


I am having trouble understanding how to receive callbacks on protocols
beyond the first one which is the http protocol right?

static const struct lws_protocols protocols[] = {

        { "http", callback_test_one, 0, 0, },
        { "connection_status", callback_test_two, 0, 0, },
        { "client_download", callback_test_three, 0, 0, },
        { NULL, NULL, 0, 0 }

};


Only my LWS_CALLBACK_PROTOCOL_INIT is called for the second and third one.
The other callbacks are never reached.

static int
callback_test_two(struct lws *wsi, enum lws_callback_reasons
reason,void *user, void *in, size_t len)
{

    switch (reason) {

        case LWS_CALLBACK_PROTOCOL_INIT:
            lwsl_user("%s: (LWS_CALLBACK_PROTOCOL_INIT) testing for
response\n", __func__);
            break;

        case LWS_CALLBACK_WSI_CREATE:
            lwsl_user("%s: (LWS_CALLBACK_WSI_CREATE) testing for
response\n", __func__);
            break;

        case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
            lwsl_user("%s: (LWS_CALLBACK_CLIENT_CONNECTION_ERROR)
testing for response\n", __func__);
            break;

        case LWS_CALLBACK_CLIENT_RECEIVE:
            lwsl_user("%s: (LWS_CALLBACK_CLIENT_RECEIVE) testing for
response\n", __func__);
            break;

        case LWS_CALLBACK_CLIENT_ESTABLISHED:
            lwsl_user("%s: (LWS_CALLBACK_CLIENT_ESTABLISHED) testing
for response\n", __func__);
            break;

        case LWS_CALLBACK_CLIENT_WRITEABLE:
            lwsl_user("%s: (LWS_CALLBACK_CLIENT_WRITEABLE) testing for
response\n", __func__);
            break;

        case LWS_CALLBACK_CLIENT_CLOSED:
            lwsl_user("%s: (LWS_CALLBACK_CLIENT_CLOSED) testing for
response\n", __func__);

        case LWS_CALLBACK_WSI_DESTROY:
            lwsl_user("%s: (LWS_CALLBACK_WSI_DESTROY) testing for
response\n", __func__);
            break;

        default:
            break;
    }
    return 0;
}

(The third is identical to this one above.)

I look in the minimal-examples ws-client and ws-server to see if there was
an example. All of those use only one protocol.

The first protocol in my list always works fine but the other two never
progress past the above issue.

Am i using protocols wrong or expecting something other than their intended
use?

If so what is the way to register different callback functions/protocols
for their client/server to utilize?

thank you for your time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200605/018b40af/attachment.htm>


More information about the Libwebsockets mailing list