[Libwebsockets] Nodejs to libwebsockets

Paolo Denti paolo.denti at gmail.com
Thu Apr 4 06:28:38 CEST 2019


Thank you Andy
I’ll look through the referenced examples

Just FYI, using the stompjs nodejs library, the default subprotocols, for
negotiation, are the ones defined as default in the library, that
are ['v10.stomp', 'v11.stomp’].
And I removed it for clarity from the code

On April 3, 2019 at 9:23:09 PM, Andy Green (andy at warmcat.com) wrote:



On April 4, 2019 12:08:05 PM GMT+08:00, Paolo Denti <paolo.denti at gmail.com>
wrote:
>Hi,
>I am trying to migrate the code below, from node.js to libwebsockets (i
>oversimplified it removing all the boilerplate code)
>Basically I need to connect, send some data and stay connected, forever
>
>I tried to find the closest option possible in the minimal examples but
>actually I am not able to replicate the behavior using any of the
>existing
>samples.

Well, they are minimal examples for particular cases. For real code, you
might have to mix and match.

>Could anyone point me to the right direction?

This shows how to do the 'nailed up client connection' and is a good
starting point.

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c

>Thanks
>
>var Stomp = require('stompjs');
>
>var connect_callback = function() {
>client.send("/ws/xx/yy/zz", {}, JSON.stringify({token: sample
>data""}));
>};
>
>var client = Stomp.overWS('wss://<my server>/<my websocket endpoint>');
>client.connect({}, connect_callback);

It looks like this doesn't specify a subprotocol, which is pretty
craptastic.

Lws can do it if you leave the client connection protocol NULL.

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c#n96

That example doesn't use tls... you'll need to set this accordingly

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c#n94

and the context / vhost options like this

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-echo/minimal-ws-client-echo.c#n141

-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20190403/9ec4272d/attachment.htm>


More information about the Libwebsockets mailing list