How to prevent libwebsockets client timeout

I am trying to create a C ++ website client using libwebsockets, but I cannot establish a connection due to turning it off. I removed everything for testing, and here is what I use to establish the connection:

Protocols

static int defaultCallback(
    struct  libwebsocket_context* context,
    struct  libwebsocket* wsi,
    enum    libwebsocket_callback_reasons reason,
    void*   user,
    void*   in,
    size_t  len)
{
    return 0;
}

static struct libwebsocket_protocols protocols[] =  {
    { "default", defaultCallback, 0 },
    { NULL, NULL, 0 }
};

Create context

    struct lws_context_creation_info info;
    memset(&info, 0, sizeof(info));
    info.port = CONTEXT_PORT_NO_LISTEN;
#ifndef LWS_NO_EXTENSIONS
    info.extensions = libwebsocket_get_internal_extensions();
#endif
    info.gid = -1;
    info.uid = -1;
    info.protocols = protocols;

    _context = libwebsocket_create_context(&info);

Create client

NOTE . The address is "ws: // localhost". I also tried "ws: //echo.websocket.org". The localhost server is a Node and ws application that I tested in Chrome and works great.

_websocket = libwebsocket_client_connect(_context, // context
                                         _address.c_str(), // address
                                         _port, // port
                                         0, // use ssl?
                                         "/", // path
                                         _address.c_str(), // host
                                         NULL, // origin
                                         NULL,  // protocol
                                         -1);   // version

Service Context

while(1) {
    libwebsocket_service(_context, 50);
}

Exit When I run above, this is the result that I get through the libwebsockets registration callback:

NOTICE: Initial logging level 1023
NOTICE: Library version: 1.4 3ae1bad
NOTICE: IPV6 not compiled in
NOTICE: libev support not compiled in
INFO:  LWS_MAX_HEADER_LEN: 1024
INFO:  LWS_MAX_PROTOCOLS: 5
INFO:  SPEC_LATEST_SUPPORTED: 13
INFO:  AWAITING_TIMEOUT: 5
INFO:  SYSTEM_RANDOM_FILEPATH: '/dev/urandom'
INFO:  LWS_MAX_ZLIB_CONN_BUFFER: 65536
NOTICE:  static allocation: 4536 + (16 x 10240 fds) = 168376 bytes
INFO:  LWS_MAX_EXTENSIONS_ACTIVE: 3
NOTICE:  canonical_hostname = an-iMac
NOTICE:  per-conn mem: 248 + 2140 headers + protocol rx buf
PARSER:   Protocol: default
CLIENT: libwebsocket_client_connect: direct conn
CLIENT: libwebsocket_client_connect_2
CLIENT: libwebsocket_client_connect_2: address ws://localhost
INFO: insert_wsi_socket_into_fds: wsi=0x7ff808514c70, sock=8, fds pos=1
CLIENT: nonblocking connect retry
INFO: TIMEDOUT WAITING on 2
DEBUG: close: just_kill_connection
INFO: remove_wsi_socket_from_fds: wsi=0x7ff808514c70, sock=8, fds pos=1
DEBUG: Connection closed before server reply

/ libwebsockets, , , . .

+4
2

"ws://". "localhost", "127.0.0.1".

0

, , . 8090 443, :

# WRONG
./lws_test_client wss://192.168.202.120 --port=8090

INSTEAD, URL:

./lws_test_client wss://192.168.202.120:8090

...

, libwebsockets. ( chrome echo- websockets.org) node ws, :

enter image description here

libwebsockets , - .

root . . - .

, , , .

: . , libwebsockets, . . , . Q & A, . , , .

# DO NOT USE: ./lws_test_client wss://192.168.202.120 --port=8090
# "wss://" will override the specific port provided!
# INSTEAD, specify it as part of the url.
./lws_test_client wss://192.168.202.120:8090
0

All Articles