[Libwebsockets] Client timing out

Mattia Romeo mromeo at giganticmechanic.com
Wed May 20 15:03:27 CEST 2015


I'm trying to create a C++ websocket client using libwebsockets but I can't establish a connection due to it timing out (I think - there may be other problems). I've stripped things down for testing and here's what I'm using to establish a 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 "ws://localhost" I've also tried "ws://echo.websocket.org". The localhost server is a Node & ws app that I've tested with Chrome and works perfectly.

_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 The Context

while(1) {
    libwebsocket_service(_context, 50);
}
Output When I run the above this is the output I get through the libwebsockets logging 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
I've looked at all the libwebsockets examples/documentation I can get my hands on and can't get any info on how to resolve this. Any help would be greatly appreciated and prevent me from putting my head through my monitor.


Thanks,
Mattia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20150520/9ee670e4/attachment.html>


More information about the Libwebsockets mailing list