websocket and http client and server library, coming with ws, a command line swiss army knife utility

Overview

Hello world

IXWebSocket is a C++ library for WebSocket client and server development. It has minimal dependencies (no boost), is very simple to use and support everything you'll likely need for websocket dev (SSL, deflate compression, compiles on most platforms, etc...). HTTP client and server code is also available, but it hasn't received as much testing.

It is been used on big mobile video game titles sending and receiving tons of messages since 2017 (iOS and Android). It was tested on macOS, iOS, Linux, Android, Windows and FreeBSD. Note that the MinGW compiler is not supported at this point. Two important design goals are simplicity and correctness.

A bad security bug affecting users compiling with SSL enabled and OpenSSL as the backend was just fixed in newly released version 11.0.0. Please upgrade ! (more details in the https://github.com/machinezone/IXWebSocket/pull/250.

/*
 *  main.cpp
 *  Author: Benjamin Sergeant
 *  Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
 *
 *  Super simple standalone example. See ws folder, unittest and doc/usage.md for more.
 *
 *  On macOS
 *  $ mkdir -p build ; (cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install)
 *  $ clang++ --std=c++11 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
 *  $ ./a.out
 *
 *  Or use cmake -DBUILD_DEMO=ON option for other platforms
 */

#include <ixwebsocket/IXNetSystem.h>
#include <ixwebsocket/IXWebSocket.h>
#include <ixwebsocket/IXUserAgent.h>
#include <iostream>

int main()
{
    // Required on Windows
    ix::initNetSystem();

    // Our websocket object
    ix::WebSocket webSocket;

    // Connect to a server with encryption
    // See https://machinezone.github.io/IXWebSocket/usage/#tls-support-and-configuration
    std::string url("wss://echo.websocket.org");
    webSocket.setUrl(url);

    std::cout << "Connecting to " << url << "..." << std::endl;

    // Setup a callback to be fired (in a background thread, watch out for race conditions !)
    // when a message or an event (open, close, error) is received
    webSocket.setOnMessageCallback([](const ix::WebSocketMessagePtr& msg)
        {
            if (msg->type == ix::WebSocketMessageType::Message)
            {
                std::cout << "received message: " << msg->str << std::endl;
                std::cout << "> " << std::flush;
            }
            else if (msg->type == ix::WebSocketMessageType::Open)
            {
                std::cout << "Connection established" << std::endl;
                std::cout << "> " << std::flush;
            }
            else if (msg->type == ix::WebSocketMessageType::Error)
            {
                // Maybe SSL is not configured properly
                std::cout << "Connection error: " << msg->errorInfo.reason << std::endl;
                std::cout << "> " << std::flush;
            }
        }
    );

    // Now that our callback is setup, we can start our background thread and receive messages
    webSocket.start();

    // Send a message to the server (default to TEXT mode)
    webSocket.send("hello world");

    // Display a prompt
    std::cout << "> " << std::flush;

    std::string text;
    // Read text from the console and send messages in text mode.
    // Exit with Ctrl-D on Unix or Ctrl-Z on Windows.
    while (std::getline(std::cin, text))
    {
        webSocket.send(text);
        std::cout << "> " << std::flush;
    }

    return 0;
}

Interested? Go read the docs! If things don't work as expected, please create an issue on GitHub, or even better a pull request if you know how to fix your problem.

IXWebSocket is actively being developed, check out the changelog to know what's cooking. If you are looking for a real time messaging service (the chat-like 'server' your websocket code will talk to) with many features such as history, backed by Redis, look at cobra.

IXWebSocket client code is autobahn compliant beginning with the 6.0.0 version. See the current test results. Some tests are still failing in the server code.

Starting with the 11.0.8 release, IXWebSocket should be fully C++11 compatible.

Users

If your company or project is using this library, feel free to open an issue or PR to amend this list.

  • Machine Zone
  • Tokio, a discord library focused on audio playback with node bindings.
  • libDiscordBot, an easy to use Discord-bot framework.
  • gwebsocket, a websocket (lua) module for Garry's Mod
  • DisCPP, a simple but feature rich Discord API wrapper
  • discord.cpp, a discord library for making bots
  • Teleport, Teleport is your own personal remote robot avatar

Alternative libraries

There are plenty of great websocket libraries out there, which might work for you. Here are a couple of serious ones.

uvweb is a library written by the IXWebSocket author which is built on top of uvw, which is a C++ wrapper for libuv. It has more dependencies and does not support SSL at this point, but it can be used to open multiple connections within a single OS thread thanks to libuv.

To check the performance of a websocket library, you can look at the autoroute project.

Continuous Integration

OS TLS Sanitizer Status
Linux OpenSSL None Build2
macOS Secure Transport Thread Sanitizer Build2
macOS OpenSSL Thread Sanitizer Build2
macOS MbedTLS Thread Sanitizer Build2
Windows Disabled None Build2
UWP Disabled None Build2
Linux OpenSSL Address Sanitizer Build2
Mingw Disabled None Build2
  • ASAN fails on Linux because of a known problem, we need a
  • Some tests are disabled on Windows/UWP because of a pathing problem
  • TLS and ZLIB are disabled on Windows/UWP because enabling make the CI run takes a lot of time, for setting up vcpkg.
Comments
  • Add close code/reason to class websocket and fix code given in callback on remote side

    Add close code/reason to class websocket and fix code given in callback on remote side

    WARNING: this PR rely on PR #41 , this last one should be merged first

    • Add close code / close reason in close() of Websocket class
    • Fix an issue about callback/code read from remote. When we close the connection using close(code, reason...), a CLOSE frame is sent to the remote, and then right after we really close the socket connection. On the remote side, the CLOSE frame data are read, then the connection is immediately closed so the close callback is called with 1006 / Abnormal close instead of the values of the CLOSE frame, because these data are not processed in the dispatch yet. The fix is to close the connection, set that we need to read the buffer, and if nothing triggered a CLOSED state with the data read, then call the callback with 1006 / Abnormal close
    • Added tests for close()
    opened by AlexandreK38 53
  • IXWebsocket with jetty + Tomcat websocket's server

    IXWebsocket with jetty + Tomcat websocket's server

    Dear @bsergean , I'm really thankful for your great project and your helpful role to respond your IXWebsocket's followers. IXWebsocket works with its own websocket's server correctly.I decided to test it with another websocket's server (Tomcat,Jetty, ......). I couldn't open and send text or binary message and the getReadyState() is onClosing. my question is : are other websocket's server supported by the IXWebsocket?

    opened by EhsanVahab 38
  • Asynchronous version of IXWebSocket::stop()

    Asynchronous version of IXWebSocket::stop()

    Heyo,

    Still a huge fan of this library. I was curious if it would be possible to get an asynchronous version of IXWebSocket::stop(). At the moment, I create the IXWebSocket instance on my main thread and I use start() to run it. In order to ensure stop() runs as fast as possible, I call close(), wait a few seconds, then I call stop() before deallocating the instance.

    However, regardless of what I do to ensure stop() executes as fast as possible, it always takes about 14ms (measured with steady_clock) for stop() to join the thread and terminate, which is too long for my main thread to block as I only have about 11ms of frame time.

    I'd love an asynchronous stop() that I can call so that way when I deallocate my IXWebSocket instance and the destructor calls the synchronous version of stop(), it completes instantly.

    I'm also open to other ways of architecting this. I'm tempted to run IXWebSocket in blocking mode on my own thread using connect(), but then I lose all of the auto-reconnect with exponential backoff logic.

    Max

    opened by maxweisel 26
  • Client can't send large messages over TLS

    Client can't send large messages over TLS

    When trying to send large messages over TLS (the smallest I could reproduce the issue is 100k) the data received in the server is messed up and server closes the connection. I tried several different clients and several different servers, the issue appears only with the IXWebSocket client connecting to different servers. I was able to debug a little bit and seems the problem appears when in SocketOpenSSL::send SSL_write returns SSL_ERROR_WANT_WRITE. After that the packets that are received in the server are not the ones being queued by the client.

    The issue can be reproduced with the following command:

    ./ws send --verify_none wss://echo.websocket.org ws
    

    Compiled latest master on Fedora 29, gcc 8.2.1, OpenSSL 1.1.1

    Some of the logging info I received: ./ws send --verify_none wss://echo.websocket.org ws [2020-01-04 20:05:01.468] [info] ws_send: Connecting to url: wss://echo.websocket.org [2020-01-04 20:05:01.468] [info] ws_send: Connecting... [2020-01-04 20:05:01.928] [info] ws_send: connected [2020-01-04 20:05:01.929] [info] Uri: / [2020-01-04 20:05:01.929] [info] Headers: [2020-01-04 20:05:01.929] [info] ws_send: Sending... [2020-01-04 20:05:01.929] [info] Connection: Upgrade [2020-01-04 20:05:01.929] [info] Date: Sat, 04 Jan 2020 20:01:01 GMT [2020-01-04 20:05:01.929] [info] Sec-WebSocket-Accept: IJCOoaSZaazYviZ5jfGFIx2E7uA= [2020-01-04 20:05:01.929] [info] Server: Kaazing Gateway [2020-01-04 20:05:01.929] [info] Upgrade: websocket [2020-01-04 20:05:02.013] [info] load file from disk completed in 84 [2020-01-04 20:05:02.724] [info] ws_send: Step 0 out of 990 [2020-01-04 20:05:02.725] [info] ws_send: Step 1 out of 990 ... [2020-01-04 20:05:03.085] [info] ws_send: Step 438 out of 990 [2020-01-04 20:05:03.085] [info] ws_send: Invalid ix::WebSocketMessageType [2020-01-04 20:05:03.086] [info] ws_send: Step 439 out of 990 ... [2020-01-04 20:05:03.213] [info] ws_send: Step 594 out of 990 [2020-01-04 20:05:03.214] [info] ws_send: Invalid ix::WebSocketMessageType [2020-01-04 20:05:03.214] [info] ws_send: Step 595 out of 990 ... [2020-01-04 20:05:03.346] [info] ws_send: Step 757 out of 990 [2020-01-04 20:05:03.347] [info] ws_send: Invalid ix::WebSocketMessageType [2020-01-04 20:05:03.347] [info] ws_send: Step 758 out of 990 ... [2020-01-04 20:05:03.369] [info] ws_send: Step 785 out of 990 [2020-01-04 20:05:03.369] [info] ws_send: Invalid ix::WebSocketMessageType [2020-01-04 20:05:03.370] [info] ws_send: Step 786 out of 990 [2020-01-04 20:05:03.371] [info] ws_send: Step 787 out of 990 [2020-01-04 20:05:03.372] [info] ws_send: Step 788 out of 990 [2020-01-04 20:05:03.372] [info] ws_send: connection closed: code 1002 reason [2020-01-04 20:05:03.372] [info] ws_send: Step 789 out of 990 ... [2020-01-04 20:05:03.534] [info] ws_send: Step 988 out of 990 [2020-01-04 20:05:03.536] [info] ws_send: Step 989 out of 990 [2020-01-04 20:05:03.537] [info] ws_send: 32180253 bytes left to be sent [2020-01-04 20:05:03.547] [info] ws_send: 32180253 bytes left to be sent ... endless retry ...

    opened by SlavSlavov 25
  • [WIP]: Tls peer verify: continued

    [WIP]: Tls peer verify: continued

    Peer verify work, continued. This is to handle the other changes that were in the pipe...I'll remove the [WIP] tag when ready.

    TODO: IXWebSocket

    • [x] OpenSSL
    • [ ] MBedTLS
    • [ ] AppleSSL
    • [ ] SChannel
    • [ ] tests
    • [x] docs

    ws cli

    • [x] send
    • [x] receive
    • [x] transfer
    • [x] connect
    • [x] echo_server
    • [x] broadcast_server
    • [x] ping
    • [x] curl
    • [ ] tests
    • [ ] docs
    opened by matt-deboer 22
  • The conan recipe is horribly outdated

    The conan recipe is horribly outdated

    The reason I'm opening this issue here is because the link to the conan recipe is in the readme. The recipe has several issues that, judging by recent commits as well, appear to be by design, or as a result of not being officially updated

    I've been wanting to try out this library, but because of incompatible build systems, I have to use Conan.

    I couldn't find IXWebSocket in any conan repository - only a recipe. So I went ahead and cloned it, and ran the command I'll be using for all these: conan create . IXWebSocket/stable. Output on the first go:

    ERROR: Failed requirement 'OpenSSL/[email protected]/stable' from 'IXWebSocket/[email protected]/stable'
    ERROR: Unable to find 'OpenSSL/[email protected]/stable' in remotes
    

    I took a look at the dependencies, and they appear to be practically identical to the ones found in the official conan repo. So I replaced the dependencies with the same versions from conan/stable. Before that, I noticed the conan recipe is actually using a fork off this repo that's over 500 commits behind, and it's running 1.5.7, which is non-existent for this repo.

    Anyway, re-run, fails:

    [ 50%] Building CXX object CMakeFiles/test_package.dir/test_package.cpp.o
    /usr/bin/clang++  -D_GLIBCXX_USE_CXX11_ABI=1 -I/root/.conan/data/IXWebSocket/1.5.7/IXWebSocket/stable/package/2d89e03e00941cc4186fea9b793094a560d9fb7b/include -I/root/.conan/data/OpenSSL/1.1.1b/conan/stable/package/e93595837cd71d31cd792a7899549d9f13bcd0cc/include -I/root/.conan/data/zlib/1.2.11/conan/stable/package/6d87124bcf4cc4435e13c44634d61b77404bef31/include  -m64 -stdlib=libstdc++ -O3 -DNDEBUG    -std=gnu++1z -o CMakeFiles/test_package.dir/test_package.cpp.o -c /programming/conanOrig/test_package/test_package.cpp
    [100%] Linking CXX executable bin/test_package
    /usr/bin/cmake -E cmake_link_script CMakeFiles/test_package.dir/link.txt --verbose=1
    /usr/bin/clang++    -m64 -stdlib=libstdc++ -O3 -DNDEBUG        -rdynamic CMakeFiles/test_package.dir/test_package.cpp.o  -o bin/test_package  -L/root/.conan/data/IXWebSocket/1.5.7/IXWebSocket/stable/package/2d89e03e00941cc4186fea9b793094a560d9fb7b/lib  -L/root/.conan/data/OpenSSL/1.1.1b/conan/stable/package/e93595837cd71d31cd792a7899549d9f13bcd0cc/lib  -L/root/.conan/data/zlib/1.2.11/conan/stable/package/6d87124bcf4cc4435e13c44634d61b77404bef31/lib -Wl,-rpath,/root/.conan/data/IXWebSocket/1.5.7/IXWebSocket/stable/package/2d89e03e00941cc4186fea9b793094a560d9fb7b/lib:/root/.conan/data/OpenSSL/1.1.1b/conan/stable/package/e93595837cd71d31cd792a7899549d9f13bcd0cc/lib:/root/.conan/data/zlib/1.2.11/conan/stable/package/6d87124bcf4cc4435e13c44634d61b77404bef31/lib -lixwebsocket -lssl -lcrypto -ldl -lpthread -lz
    /root/.conan/data/IXWebSocket/1.5.7/IXWebSocket/stable/package/2d89e03e00941cc4186fea9b793094a560d9fb7b/lib/libixwebsocket.a(IXSocketFactory.cpp.o): In function `ix::createSocket(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
    IXSocketFactory.cpp:(.text+0x52): undefined reference to `ix::SocketOpenSSL::SocketOpenSSL(int)'
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    CMakeFiles/test_package.dir/build.make:97: recipe for target 'bin/test_package' failed
    make[2]: *** [bin/test_package] Error 1
    make[2]: Leaving directory '/programming/conanOrig/test_package/build/47edf16f7c6208a569a5a85106a6734e405b9db6'
    CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/test_package.dir/all' failed
    make[1]: *** [CMakeFiles/test_package.dir/all] Error 2
    make[1]: Leaving directory '/programming/conanOrig/test_package/build/47edf16f7c6208a569a5a85106a6734e405b9db6'
    Makefile:86: recipe for target 'all' failed
    make: *** [all] Error 2
    ERROR: IXWebSocket/[email protected]/stable (test package): Error in build() method, line 15
            cmake.build()
            ConanException: Error 512 while executing cmake --build '/programming/conanOrig/test_package/build/47edf16f7c6208a569a5a85106a6734e405b9db6' '--' '-j1'
    

    When I was setting this up, I didn't notice the version. So I replaced the homepage URL without replacing the version, which resulted in another exception when it tried to get the archive, because 1.5.7 doesn't exist in this repo. I bumped the version as well, re-build, and:

    [ 50%] Building CXX object CMakeFiles/test_package.dir/test_package.cpp.o
    /usr/bin/clang++  -D_GLIBCXX_USE_CXX11_ABI=1 -I/root/.conan/data/IXWebSocket/5.0.0/IXWebSockets/stable/package/2d89e03e00941cc4186fea9b793094a560d9fb7b/include -I/root/.conan/data/OpenSSL/1.1.1b/conan/stable/package/e93595837cd71d31cd792a7899549d9f13bcd0cc/include -I/root/.conan/data/zlib/1.2.11/conan/stable/package/6d87124bcf4cc4435e13c44634d61b77404bef31/include  -m64 -stdlib=libstdc++ -O3 -DNDEBUG    -std=gnu++1z -o CMakeFiles/test_package.dir/test_package.cpp.o -c /programming/conan-IXWebSocket/test_package/test_package.cpp
    /programming/conan-IXWebSocket/test_package/test_package.cpp:23:30: error: no member named 'WebSocket_MessageType_Message' in namespace 'ix'
          if (messageType == ix::WebSocket_MessageType_Message) {
                             ~~~~^
    /programming/conan-IXWebSocket/test_package/test_package.cpp:24:14: error: no member named 'cout' in namespace 'std'
            std::cout << str << std::endl;
            ~~~~~^
    /programming/conan-IXWebSocket/test_package/test_package.cpp:24:34: error: no member named 'endl' in namespace 'std'
            std::cout << str << std::endl;
                                ~~~~~^
    /programming/conan-IXWebSocket/test_package/test_package.cpp:17:5: error: no viable conversion from '(lambda at /programming/conan-IXWebSocket/test_package/test_package.cpp:17:5)' to 'const ix::OnMessageCallback'
          (aka 'const function<void (const shared_ptr<ix::WebSocketMessage> &)>')
        [](ix::WebSocketMessageType messageType,
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_function.h:421:7: note: candidate constructor not viable: no known conversion from '(lambda at /programming/conan-IXWebSocket/test_package/test_package.cpp:17:5)' to
          'std::nullptr_t' (aka 'nullptr_t') for 1st argument
          function(nullptr_t) noexcept
          ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_function.h:432:7: note: candidate constructor not viable: no known conversion from '(lambda at /programming/conan-IXWebSocket/test_package/test_package.cpp:17:5)' to
          'const std::function<void (const std::shared_ptr<ix::WebSocketMessage> &)> &' for 1st argument
          function(const function& __x);
          ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_function.h:441:7: note: candidate constructor not viable: no known conversion from '(lambda at /programming/conan-IXWebSocket/test_package/test_package.cpp:17:5)' to
          'std::function<void (const std::shared_ptr<ix::WebSocketMessage> &)> &&' for 1st argument
          function(function&& __x) noexcept : _Function_base()
          ^
    /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/std_function.h:465:2: note: candidate template ignored: substitution failure
          [with _Functor = (lambda at /programming/conan-IXWebSocket/test_package/test_package.cpp:17:5), $1 = void]: no type named 'type' in 'std::result_of<(lambda at /programming/conan-IXWebSocket/test_package/test_package.cpp:17:5) &(const
          std::shared_ptr<ix::WebSocketMessage> &)>'
            function(_Functor);
            ^
    /programming/conan-IXWebSocket/test_package/test_package.cpp:17:5: note: candidate function
        [](ix::WebSocketMessageType messageType,
        ^
    /root/.conan/data/IXWebSocket/5.0.0/IXWebSockets/stable/package/2d89e03e00941cc4186fea9b793094a560d9fb7b/include/ixwebsocket/IXWebSocket.h:80:60: note: passing argument to parameter 'callback' here
            void setOnMessageCallback(const OnMessageCallback& callback);
                                                               ^
    4 errors generated.
    CMakeFiles/test_package.dir/build.make:65: recipe for target 'CMakeFiles/test_package.dir/test_package.cpp.o' failed
    make[2]: *** [CMakeFiles/test_package.dir/test_package.cpp.o] Error 1
    make[2]: Leaving directory '/programming/conan-IXWebSocket/test_package/build/47edf16f7c6208a569a5a85106a6734e405b9db6'
    CMakeFiles/Makefile2:70: recipe for target 'CMakeFiles/test_package.dir/all' failed
    make[1]: *** [CMakeFiles/test_package.dir/all] Error 2
    make[1]: Leaving directory '/programming/conan-IXWebSocket/test_package/build/47edf16f7c6208a569a5a85106a6734e405b9db6'
    Makefile:86: recipe for target 'all' failed
    make: *** [all] Error 2
    ERROR: IXWebSocket/[email protected]/stable (test package): Error in build() method, line 15
            cmake.build()
            ConanException: Error 512 while executing cmake --build '/programming/conan-IXWebSocket/test_package/build/47edf16f7c6208a569a5a85106a6734e405b9db6' '--' '-j1'
    

    I also actually can't find some of these fields in the fork. The new variant (WebSocketMessageType, as outlined in the readme of this project) at least exists in this repo. The file in question also only exists here - I can't find either of these in the repo the recipe points to.

    Also, off the top of my head, this will probably fail (if that's an actual concept - I'm not that familiar with developing Conan recipes myself), because not everyone happens to have a websocket server at localhost:8080 running.

    So for the hell of it, I used my fixed package to test. I used the example using localhost:8080 on the main site, with the imports:

    #include <iostream>
    #include <ixwebsocket/IXWebSocket.h>
    #include <ixwebsocket/IXSocket.h>
    #include <ixwebsocket/IXWebSocketMessageType.h>
    

    as well as the conan package I built and a basic CMakeLists.txt I pretty much borrowed from the Conan docs. It compiled with no errors.

    But to get there, I had to change the repo, bump the version, and remove the tests (while updating the test could've worked as well, I'm not familiar with the library, or creating conan recipes, so I didn't want to push my luck).

    Could the conan recipe be updated? Pushing it to conan-center as well could be a good idea.

    opened by LunarWatcher 22
  • Uploading files through multipart.

    Uploading files through multipart.

    I'm working on my DisC++ lib and I think I got all the basic http methods done. I just need to work on uploading files. Discord does this via a multipart form.

    You did give me an example in an earlier issue, which I was able to track down. But it doesn't really help me much.

    In that method you use miniDumpBytes which is a string, how would I get the minidump bytes for the files from an ifstream? And what about sending multiple files in one request? If you want to look at the documentation on sending files, its here.

    Thanks for reading!

    bug no-issue-activity 
    opened by SeanOMik 20
  • WebSocket server dies on multiple connection attempts from same client

    WebSocket server dies on multiple connection attempts from same client

    Major conclustion: The situation is worse than we thought Initially.. I thought this to be a result of trying to close the socket within the setOnConnectionCallback() method. The reality is that if we have a client constantly trying to open new sockets the server throws and dies within a few seconds.

     _onMessageCallback(
                std::make_unique<WebSocketMessage>(WebSocketMessageType::Open,
                                                   "",
                                                   0,
                                                   WebSocketErrorInfo(),
                                                   WebSocketOpenInfo(status.uri, status.headers),
                                                   WebSocketCloseInfo()));
    

    What we initially thought: Situation: the client (Chrome) is invoking multiple socket instances. When we decide to close within setOnConnectionCallback() the server 'explodes' at the above line.

    It occurs within setOnConnectionCallback() i.e. we want to limit the number of active connections from a single IP thus send error MSG and close the socket right within the onConnectionCallback

    Update: I read up (by looking at an example) within documentation that stop() is used is used instead of close(), still close is a public method.What's the difference? When using stop() the result is the same.

    end()/close() executes, then webSocketServer's handleConnection() kicks in, and throws at connectToSocket(), the socket param is null and timout -3.

    opened by rafalsk 19
  • Add support for supplying SSL CA from memory

    Add support for supplying SSL CA from memory

    Heyo,

    I'm using IXWebSocket with a websocket service that's over HTTPS. The service uses letsencrypt, and on platforms like macOS and iOS, it works perfectly. The system Security.framework can verify the certificate using the system's trusted CAs.

    However, on Windows, it fails to verify the chain. As far as I know, mbedtls and openssl do not have the ability to automatically load system trusted CAs on Windows. My project already compiles a static version of openssl, so on non-Apple platforms, I'm using USE_OPENSSL instead of mbed_tls.

    I'd love to implement an API on IXSocketTLSOptions that allows you to specify a CA or cert/key pair from memory. I'm happy to write the implementation for this. I figured I'd write up a github issue in case you have any opinions on how I should go about implementing it.

    Max

    opened by maxweisel 18
  • android can not recieve message

    android can not recieve message

    I make a dll for unity3d , It works fine on windows , But Not ok on android . the url is "wss://xxxx:“。 ” , I track the code, final I get the error in the "IXNetSystem.cpp" ::poll(fds, nfds, timeout); the function always return -1 and the errorno is alaways 4. how can I fixed , forgive my pool english

    opened by shiliupingGitHub 17
  • If a socket connection is interrupted, calling stop() on the IXWebSocket object blocks until the next retry.

    If a socket connection is interrupted, calling stop() on the IXWebSocket object blocks until the next retry.

    I'm using an IXWebSocket object. When my application is ready to shut down, I call stop() on the socket object. When the connection is open, this works perfectly. However, if the connection has been severed, IXWebSocket blocks until the next retry attempt which can be up to 10 seconds.

    Steps to reproduce:

    1. Create an IXWebSocket object, call setURL with any URL that is unreachable, and call start()
    2. IXWebSocket will begin retrying with exponential backoff. Once it hits 10 seconds, call stop() immediately after a failed retry.
    3. Observe that stop() will block for 10 seconds until a retry occurs.

    I did some digging, and it seems stop() blocks on _thread.join(). Personally, I still want to keep stop() synchronous. I don't think that's the issue. It seems the issue is that the thread that IXWebSocket uses is blocked while waiting to try to reconnect.

    Any recommendations here? I'm happy to create a fix and open a PR, but I'm not familiar enough with IXWebSocket to know what approach would be in-line with how you've designed the library.

    Max

    opened by maxweisel 16
  •  CPU utility is  too high

    CPU utility is too high

    400%cpu 121%user 10%nice 81%sys 183%idle 0%iow 4%irq 2%sirq 0%host PID USER PR NI VIRT RES SHR S[%CPU] %MEM TIME+ ARGS
    4680 shell 20 0 11M 2.0M 1.5M S 100 0.0 7:02.65 demo 32676 u0_a189 20 0 1.6G 170M 59M S 83.3 4.5 23:32.87 cn.alios.voiceservice 5177 u0_a182 16 -4 2.1G 149M 73M S 8.6 3.9 0:08.36 com.xunmeng.pinduoduo 1629 u0_a90 20 0 4.8G 68M 43M S 3.6 1.7 2:30.81 com.ustwo.lwp 4748 shell 20 0 35M 3.0M 1.7M R 3.0 0.0 0:11.06 top 506 system -2 -8 288M 12M 8.1M S 2.0 0.3 10:31.96 surfaceflinger 5101 root 20 0 0 0 0 S 1.3 0.0 0:00.62 [kworker/u8:5] 929 system 18 -2 8.0G 322M 247M S 1.3 8.5 5:21.26 system_server 525 root RT 0 0 0 0 D 1.3 0.0 2:33.75 [mdss_fb0] 26043 root 20 0 0 0 0 S 1.0 0.0 0:05.91 [kworker/0:5] 672 system RT 0 2.0G 3.9M 2.5M S 1.0 0.1 0:43.33 [email protected] 25136 root 20 0 0 0 0 S 0.6 0.0 0:43.88 [kworker/u8:8] 770 shell 20 0 148M 4.0M 2.3M S 0.6 0.1 0:36.47 adbd --root_seclabel=u:r:su:s0 508 system -3 -8 151M 4.2M 3.2M S 0.6 0.1 2:43.89 [email protected] 354 root RT 0 0 0 0 S 0.6 0.0 0:29.94 [nanohub] 276 root RT 0 0 0 0 S 0.6 0.0 0:11.26 [spi6] 4638 root 20 0 0 0 0 S 0.3 0.0 0:02.91 [kworker/0:1] 4327 root 20 0 0 0 0 S 0.3 0.0 0:03.61 [kworker/0:0] 2013 u0_a182 20 0 1.8G 71M 45M S 0.3 1.8 0:03.88 com.xunmeng.pinduoduo:titan 1872 root 20 0 0 0 0 S 0.3 0.0 0:12.90 [kworker/u8:2] 26054 shell 20 0 33M 1.9M 1.3M S 0.3 0.0 0:02.75 logcat -v long -v epoch 2896 u0_a176 20 0 6.7G 132M 68M S 0.3 3.5 0:41.87 com.tencent.mm 1990 root 18 -2 0 0 0 S 0.3 0.0 0:14.61 [VosMCThread] 1784 radio 20 0 5.3G 68M 34M S 0.3 1.8 0:09.42 com.android.phone

    hi. i test the demo.the CPU utility is too high,what can do for reducing it?

    opened by liuxiaofeng8888 5
  • IXWebSocket client creates a lot of threads when connecting to some urls

    IXWebSocket client creates a lot of threads when connecting to some urls

    After start() method IXWebSocket creates around 30 threads when connecting to some urls. wss is using. One of that threads is using to send messages, one for receiving. How can I force IXWebSocket to use only one thread (like for other urls)? Compiled with "cmake -DUSE_TLS=1 -DUSE_ZLIB=1 -DUSE_OPEN_SSL=1 .." Attached screenshots screen 2 screen 1 .

    opened by Ringflash 10
  • add Content-Type support

    add Content-Type support

    image

    image

    image

    The old version of IXWebSocket did not correctly handle the front-end static file type, causing the front-end page rendering to fail.

    The browser needs to recognize the Content-Type parameter to determine the file type for rendering, so it is necessary to manually declare the Content-Type parameter.

    opened by mochazi 1
  • IXWebSocketServer hangs on OpenSSL handshake

    IXWebSocketServer hangs on OpenSSL handshake

    WebSocket server occasionally stops accepting new connections probably when SSL handshake is interrupted in the right moment. I use OpenSSL, so IXSocketOpenSSL.cpp is relevant here. It is possible that this is not IXWebSocket bug but an OpenSSL bug, but if it is so, is there an OpenSSL version one should avoid? This is a rare thing to happen, so I wasn't lucky enough to catch it on both client and server side. Here is a backtrace from gdb:

     (gdb) bt
    #0  0x00007f2b99edf8e4 in read () from /lib64/libpthread.so.0
    #1  0x00007f2b9a1a1132 in sock_read () from /lib64/libcrypto.so.1.1
    #2  0x00007f2b9a19a85e in bread_conv () from /lib64/libcrypto.so.1.1
    #3  0x00007f2b9a1996c3 in bio_read_intern () from /lib64/libcrypto.so.1.1
    #4  0x00007f2b9a199c77 in BIO_read () from /lib64/libcrypto.so.1.1
    #5  0x00007f2b99a4836f in ssl3_read_n () from /lib64/libssl.so.1.1
    #6  0x00007f2b99a4c63e in ssl3_get_record () from /lib64/libssl.so.1.1
    #7  0x00007f2b99a49f40 in ssl3_read_bytes () from /lib64/libssl.so.1.1
    #8  0x00007f2b99a7e19d in tls_get_message_header () from /lib64/libssl.so.1.1
    #9  0x00007f2b99a73938 in state_machine.part () from /lib64/libssl.so.1.1
    #10 0x00007f2b99a5ec98 in SSL_do_handshake () from /lib64/libssl.so.1.1
    #11 0x00000000005d30ad in ix::SocketOpenSSL::openSSLServerHandshake(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ()
    #12 0x00000000005d420d in ix::SocketOpenSSL::accept(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) ()
    #13 0x00000000005a87c3 in ix::SocketServer::run() ()
    #14 0x00000000005aa384 in void std::__invoke_impl<void, void (ix::SocketServer::*)(), ix::SocketServer*>(std::__invoke_memfun_deref, void (ix::SocketServer::*&&)(), ix::SocketServer*&&) ()
    #15 0x00000000005a9712 in std::__invoke_result<void (ix::SocketServer::*)(), ix::SocketServer*>::type std::__invoke<void (ix::SocketServer::*)(), ix::SocketServer*>(void (ix::SocketServer::*&&)(), ix::SocketServer*&&) ()
    #16 0x00000000005abd67 in decltype (__invoke((_S_declval<0ul>)(), (_S_declval<1ul>)())) std::thread::_Invoker<std::tuple<void (ix::SocketServer::*)(), ix::SocketServer*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) ()
    #17 0x00000000005abc9a in std::thread::_Invoker<std::tuple<void (ix::SocketServer::*)(), ix::SocketServer*> >::operator()() ()
    #18 0x00000000005abc64 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (ix::SocketServer::*)(), ix::SocketServer*> > >::_M_run() ()
    #19 0x00007f2b99750ba3 in execute_native_thread_routine () from /lib64/libstdc++.so.6
    #20 0x00007f2b99ed614a in start_thread () from /lib64/libpthread.so.0
    #21 0x00007f2b98e2df23 in clone () from /lib64/libc.so.6
    (gdb) info threads
      Id   Target Id                                           Frame 
      1    Thread 0x7f2b9b913500 (LWP 93887) "main_thread"    0x00007f2b99edc2fc in [email protected]@GLIBC_2.3.2 () from /lib64/libpthread.so.0
      2    Thread 0x7f2b98712700 (LWP 93888) "periodic_operations"    0x00007f2b99edffb0 in nanosleep () from /lib64/libpthread.so.0
    * 3    Thread 0x7f2b97f11700 (LWP 93889) "SocketServer::a" 0x00007f2b99edf8e4 in read () from /lib64/libpthread.so.0
      4    Thread 0x7f2b97710700 (LWP 93890) "SocketServer::G" 0x00007f2b99edc2fc in [email protected]@GLIBC_2.3.2 () from /lib64/libpthread.so.0
      5    Thread 0x7f2b96f0f700 (LWP 182437) ""               0x00007f2b98e22ca1 in poll () from /lib64/libc.so.6
    
    opened by rossum2 2
  • Add option to disable hostname check

    Add option to disable hostname check

    This adds a new option that disables the hostname check for received certificates. This is useful in setups where one knows that a host's name won't align with the certificate.

    The option is only implemented for OpenSSL right now, as that's where I need it. I can't easily test the other SSL implementations, so I figured I submit this as is for now to see what you think about it.

    opened by rsmmr 3
Releases(v11.4.3)
Owner
Machine Zone, Inc.
Machine Zone, Inc.
Pushpin is a reverse proxy server written in C++ that makes it easy to implement WebSocket, HTTP streaming, and HTTP long-polling services.

Pushpin is a reverse proxy server written in C++ that makes it easy to implement WebSocket, HTTP streaming, and HTTP long-polling services. The project is unique among realtime push solutions in that it is designed to address the needs of API creators. Pushpin is transparent to clients and integrates easily into an API stack.

Fanout 3.1k Sep 14, 2022
Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution

CppServer Ultra fast and low latency asynchronous socket server & client C++ library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and

Ivan Shynkarenka 885 Sep 17, 2022
Mongoose Embedded Web Server Library - a multi-protocol embedded networking library with TCP/UDP, HTTP, WebSocket, MQTT built-in protocols, async DNS resolver, and non-blocking API.

Mongoose - Embedded Web Server / Embedded Networking Library Mongoose is a networking library for C/C++. It implements event-driven non-blocking APIs

Cesanta Software 8.7k Sep 18, 2022
cuehttp is a modern c++ middleware framework for http(http/https)/websocket(ws/wss).

cuehttp 简介 cuehttp是一个使用Modern C++(C++17)编写的跨平台、高性能、易用的HTTP/WebSocket框架。基于中间件模式可以方便、高效、优雅的增加功能。cuehttp基于boost.asio开发,使用picohttpparser进行HTTP协议解析。内部依赖了nl

xcyl 27 Aug 15, 2022
H2O - the optimized HTTP/1, HTTP/2, HTTP/3 server

H2O - an optimized HTTP server with support for HTTP/1.x, HTTP/2 and HTTP/3 (experimental) Copyright (c) 2014-2019 DeNA Co., Ltd., Kazuho Oku, Tatsuhi

H2O 10.1k Sep 20, 2022
Cross-platform, efficient, customizable, and robust asynchronous HTTP/WebSocket server C++14 library with the right balance between performance and ease of use

What Is RESTinio? RESTinio is a header-only C++14 library that gives you an embedded HTTP/Websocket server. It is based on standalone version of ASIO

Stiffstream 882 Sep 19, 2022
C++ websocket client/server library

WebSocket++ (0.8.2) WebSocket++ is a header only C++ library that implements RFC6455 The WebSocket Protocol. It allows integrating WebSocket client an

Peter Thorson 5.8k Sep 22, 2022
Small and fast cross-platform networking library, with support for messaging, IPv6, HTTP, SSL and WebSocket.

frnetlib Frnetlib, is a cross-platform, small and fast networking library written in C++. There are no library dependencies (unless you want to use SS

Fred Nicolson 22 May 16, 2022
BingBing 58 Sep 17, 2022
aria2 is a lightweight multi-protocol & multi-source, cross platform download utility operated in command-line.

aria2 is a lightweight multi-protocol & multi-source, cross platform download utility operated in command-line. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink.

aria2 27.5k Sep 21, 2022
HTTP and WebSocket built on Boost.Asio in C++11

HTTP and WebSocket built on Boost.Asio in C++11 Branch Linux/OSX Windows Coverage Documentation Matrix master develop Contents Introduction Appearance

Boost.org 3.5k Sep 20, 2022
Simple embeddable C++11 async tcp,http and websocket serving.

net11 Simple embeddable C++11 async tcp,http and websocket serving. What is it? An easily embeddable C++11 networking library designed to make buildin

Jonas Lund 9 Mar 28, 2020
A Lightweight and fully asynchronous WebSocket client library based on libev

libuwsc(中文) A Lightweight and fully asynchronous WebSocket client library based on libev for Embedded Linux. And provide Lua-binding. Why should I cho

Jianhui Zhao 284 Jul 7, 2022
Gromox - Groupware server backend with MAPI/HTTP, RPC/HTTP, IMAP, POP3 and PHP-MAPI support for grommunio

Gromox is the central groupware server component of grommunio. It is capable of serving as a replacement for Microsoft Exchange and compatibles. Conne

grommunio 121 Sep 16, 2022
A collection of C++ HTTP libraries including an easy to use HTTP server.

Proxygen: Facebook's C++ HTTP Libraries This project comprises the core C++ HTTP abstractions used at Facebook. Internally, it is used as the basis fo

Facebook 7.6k Sep 22, 2022
A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio.

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.

Ole Christian Eidheim 2.4k Sep 17, 2022
A C++ header-only HTTP/HTTPS server and client library

cpp-httplib A C++11 single-file header-only cross platform HTTP/HTTPS library. It's extremely easy to setup. Just include the httplib.h file in your c

null 7.8k Sep 26, 2022
WSServer is a fast, configurable, and extendable WebSocket Server for UNIX systems written in C (C11).

WSServer a C WebSocket Server WSServer is a fast, configurable, and extendable WebSocket Server for UNIX systems written in C (C11). As of version 2.0

Morten Houmøller Nygaard 168 Sep 14, 2022
Various utilities such as WebServer, JSON, WebSocket server, REST framework

DumaisLib This is a library containing several utilities for some projects of Patrick Dumais. Previously, the libraries were all individual but it bec

Patrick Dumais 25 Feb 22, 2022