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

Sumit Dubey sumitd2002 at yahoo.com
Thu Feb 27 09:01:15 CET 2020

Now I have a problem binding to all or a specific interface on linux:
[2020/02/27 07:56:58:9752] N:  Vhost 'default' using TLS mode[2020/02/27 07:56:58:9757] N:  SSL ECDH curve 'prime256v1'[2020/02/27 07:56:58:9759] E: ERROR on binding fd 6 to port 80 (-1 13)[2020/02/27 07:56:58:9759] E: VH default: iface eth0/null port 80 DOESN'T EXIST
The same code (info.iface=NULL;) works on windows.
    On Wednesday, 5 February 2020, 02:22:01 pm GMT+5:30, Sumit Dubey <sumitd2002 at yahoo.com> wrote:  
  Thank you Andy, LWS_SERVER_OPTION_DISABLE_IPV6 works.Sumit
    On Tuesday, 4 February 2020, 03:12:03 pm GMT+5:30, Andy Green <andy at warmcat.com> wrote:  

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).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200227/e8bde299/attachment.htm>

More information about the Libwebsockets mailing list