nginxwebsocketnetwork-programmingprotocolslibwebsockets

How to communicate between a libwebsockets client and a websocket server like Nginx?


I try to implement a websocket client (with libwebsockets in C and it's not an option). As example, i used the test-client.c given with the library. My websocket-client actualy works fine with the test-server.c . But i experienced some complications to communicate with an nginx server.

As i understand, the handshack doesn't end up well because nginx doesn't know my websocket client's sub-protocol. Well, it appears, like in test-client.c i'm implementing my own sub-protocol (with its own name, its own callback function).

My questions are :

Any help is appreciated. Thanks!


Solution

  • As discussed with Andy, the libwebsockets designer (https://github.com/warmcat/libwebsockets/issues/834), the simpliest way to make it works is to not named the sub-protocol in the structure defining the websocket sub-protocol client's side :

    /* list of supported sub-protocols and callbacks */
    static struct lws_protocols ws_protocols[] = {
            { NULL, ws_callback, 0, 128, },
            { NULL, NULL, 0, 0 } /* end */
    };
    

    Libwebsockets client doesn't try to negociate with sec-websocket-protocol in the header, the handshake works just fine with nginx.