[Libwebsockets] lws_create_context() not binding to all interfaces on windows

Andy Green andy at warmcat.com
Tue Feb 4 10:41:59 CET 2020

On 2/4/20 8:19 AM, Sumit Dubey wrote:
> Hello,
> info.port = 80;
> info.iface = NULL;

If it's not bound to any particular IP, it should accept connections 
from anywhere to that port

> lws_create_context(&info) succeeds, with the following netstat entry:
>   TCP    [::]:80                DESKTOP-5D1FDJI:0      LISTENING

It's listening on ipv6... if I have LWS_IPV6=1 and listen on the test 
server, I get basically the same on linux

tcp6       0      0 :::7681                 :::* 
LISTEN      1593017/libwebsocke

If all you want is to disable ipv6, you can use the cmake option 
-DLWS_IPV6=0 and everything will happen on ipv4.

> The http service is only accessible by the address http://localhost 
> <http://localhost.>
> http:// <http://<local-ip>><local-ip> and http:// 
> <http://<public-ip>><public-ip> both fail with "connection refused".

On Linux, I can, eg

telnet 7681
telnet ::1 7681

and both work OK.  At least on Fedora, /etc/hosts is prepared with local 
aliases "localhost4" and "localhost6" that work the same.

Because somebody is already listening on :::7681 Linux won't let you 
open a listen socket on additionally.  But it'd be OK 
with that if you were listening on ::1:7681 (ie, the ipv6 address for lo 
network interface) and wanted to open another listening socket on  You should be able to set info.iface to indicate the IP 
or network interface name you want it to bind to.

If you want to listen on both, create two vhosts set up with the same 
info struct, except one has LWS_SERVER_OPTION_DISABLE_IPV6.

This example shows how to create the vhosts explicitly


You'd set the info.options flag LWS_SERVER_OPTION_DISABLE_IPV6 before 
creating the vhost bound to "" (at least that's how it'd be on 
Linux AFAIK).


More information about the Libwebsockets mailing list