[Libwebsockets] Internet versus LAN connections

Andy Green andy at warmcat.com
Tue Aug 12 00:49:23 CEST 2014



On 12 August 2014 00:15:13 GMT+08:00, Willem Burgers <wa.burgers+lws at gmail.com> wrote:
>Hi,
>
>I have a libwebsockets server running.
>Whenever I try to connect over LAN, it works perfectly fine, but when I
>try
>to connect over the Internet, the connection times out with error code
>1006.
>I have forwarded the websocket port on my router to the correct port
>for
>the server.
>In the JavaScript of the page I use the external IP obviously.
>I tried a NodeJS echo server, which works fine over the Internet.
>Also the libwebsockets-test-server works perfectly fine.

Well, if the test server can work, there should be no problem on the library side.

>My HTTP callback just returns 0, because the html file is hosted on
>another
>machine.
>
>static int httpCallback(struct libwebsocket_context *context,
>struct libwebsocket *wsi,
>enum libwebsocket_callback_reasons reason,
> void *user, void *in, size_t len) {
>    return 0;
>}
>
>Should this be changed for libwebsockets to work over the Internet?

No although I never tried it, it should be ok.

>Does it need to accept the Upgrade http request itself?

Yes lws must get the upgrade request.  Otherwise is neither knows you want a websocket connection nor what protocol etc

>If so, why does it work over LAN connections?

I suspect you're confusing the general http serving support done by the user callback, with the handling of the upgrade request, which is done by the library itself since it is required for any websocket connection.  If so it's a red herring.

What I would do is 1) tcpdump the handshake from both sides and if that doesn't help, 2) replace my user code with user code from the test server.  If that works, change it back to your code piece by piece until it breaks again.

-Andy

>Thanks,
>Willem
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list