websocket and http client and server library, with TLS support and very few dependencies
Go to file
2020-11-11 09:16:14 -08:00
.github/workflows add a github action to publish a docker container for ws 2020-09-02 11:52:59 -07:00
CMake (cmake) DEFLATE -> Deflate in CMake to stop warnings about casing 2020-11-07 09:40:54 -08:00
docker fix docker and linux build 2020-09-28 11:56:49 -07:00
docs (openssl security fix) in the client to server connection, peer verification is not done in all cases. See https://github.com/machinezone/IXWebSocket/pull/250 2020-11-11 09:16:14 -08:00
ixbots (cmake) Stop using FetchContent cmake module to retrieve jsoncpp third party dependency 2020-09-30 14:24:04 -07:00
ixcobra (cmake) Stop using FetchContent cmake module to retrieve jsoncpp third party dependency 2020-09-30 14:24:04 -07:00
ixcore core logger support multiple level + switch ixbots to user corelogger instead of spdlog 2020-04-24 15:17:50 -07:00
ixcrypto (ws) add gzip and gunzip ws sub commands 2020-09-28 10:19:27 -07:00
ixredis (socket servers) merge the ConnectionInfo class with the ConnectionState one, which simplify all the server apis 2020-08-28 14:55:40 -07:00
ixsentry (cmake) Stop using FetchContent cmake module to retrieve jsoncpp third party dependency 2020-09-30 14:24:04 -07:00
ixsnake (socket servers) merge the ConnectionInfo class with the ConnectionState one, which simplify all the server apis 2020-08-28 14:55:40 -07:00
ixwebsocket (openssl security fix) in the client to server connection, peer verification is not done in all cases. See https://github.com/machinezone/IXWebSocket/pull/250 2020-11-11 09:16:14 -08:00
test (ws autoroute) Display result in compliant way (AUTOROUTE IXWebSocket :: N ms) so that result can be parsed easily 2020-11-07 09:34:54 -08:00
third_party (cmake) Stop using FetchContent cmake module to retrieve jsoncpp third party dependency 2020-09-30 14:24:04 -07:00
tools add tool to ease making commits 2020-07-24 11:53:09 -07:00
ws (ws autoroute) Display result in compliant way (AUTOROUTE IXWebSocket :: N ms) so that result can be parsed easily 2020-11-07 09:34:54 -08:00
.clang-format update clang format file 2019-09-10 22:17:08 -07:00
.dockerignore fix cobra to sentry + change ws docker file to use alpine (much smaller footprint) 2019-05-31 00:43:22 -07:00
.gitignore update .gitignore file 2020-06-01 17:01:59 -07:00
.pre-commit-config.yaml fix #182 2020-04-22 14:26:16 -07:00
appveyor.yml update appveyor file to new directory structure 2019-09-10 12:33:47 -07:00
CMakeLists.txt (cmake) DEFLATE -> Deflate in CMake to stop warnings about casing 2020-11-07 09:40:54 -08:00
docker-compose.yml (ws) echo_client command renamed to autoroute. Command exit once the server close the connection. push_server commands exit once N messages have been sent. 2020-09-03 09:13:23 -07:00
Dockerfile use alpine as the docker distribution 2020-03-27 17:38:35 -07:00
httpd.cpp embedded help for httpd tool 2020-06-01 17:01:12 -07:00
LICENSE.txt First import 2018-09-27 14:57:19 -07:00
main.cpp fix #210 / better standalone example, an echo client 2020-05-27 16:24:33 -07:00
makefile (docker) build docker container with zlib disabled 2020-11-07 11:22:52 -08:00
mkdocs.yml use default mkdocs theme 2020-04-04 11:05:14 -07:00
README.md Update README.md (#249) 2020-11-01 18:17:12 -08:00
SECURITY.md Create SECURITY.md 2019-10-17 06:58:22 -07:00

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.

/*
 *  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++14 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
 *  $ ./a.out
 */

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

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

    // Our websocket object
    ix::WebSocket webSocket;

    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;
            }
            else if (msg->type == ix::WebSocketMessageType::Open)
            {
                std::cout << "Connection established" << std::endl;
            }
        }
    );

    // 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");

    while (true)
    {
        std::string text;
        std::cout << "> " << std::flush;
        std::getline(std::cin, text);

        webSocket.send(text);
    }

    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.

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

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