{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"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;}return0;}Interested?Goreadthedocs!Ifthingsdon'tworkasexpected,pleasecreateanissueonGitHub,orevenbetterapullrequestifyouknowhowtofixyourproblem.IXWebSocketisactivelybeingdeveloped,checkoutthechangelogtoknowwhat'scooking.Ifyouarelookingforarealtimemessagingservice(thechat-like'server'yourwebsocketcodewilltalkto)withmanyfeaturessuchashistory,backedbyRedis,lookatcobra.IXWebSocketclientcodeisautobahncompliantbeginningwiththe6.0.0version.Seethecurrenttestresults.Sometestsarestillfailingintheservercode.Startingwiththe11.0.8release,IXWebSocketshouldbefullyC++11compatible.UsersIfyourcompanyorprojectisusingthislibrary,feelfreetoopenanissueorPRtoamendthislist.MachineZoneTokio,adiscordlibraryfocusedonaudioplaybackwithnodebind