[Libwebsockets] how to retrieve the url websocket from javascript using libwebsockets ??

Andy Green andy at warmcat.com
Wed Mar 11 01:27:23 CET 2015

On 11 March 2015 00:48:59 GMT+08:00, Mefteh Safa <mefteh.safa9 at gmail.com> wrote:
>I want to know how can i get the url of the websocket created (var
>websocket = new Websocket(*url*, protocol)) from the JS using the
>libWebSockets. I tried to print the wsi->c_path but always it was null.
>please help me .

The headers that came from the client at the handshake get chopped up into tokenized arrays, since there's potentially a lot of interesting headers and they need to be stored in a space-efficient way.

1) enum lws_token_indexes {
 in libwebsockets.h

2) see dump_handshake_info() on the test server code for how to read the tokenized strings

3) If this is a websocket protocol connection, the tokenized headers are deleted after the LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION callback, which is sent on the protocol-specific callback (not always protocol 0).  So you should service that callback, and save any of the tokens you are interested in.


>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list