{"id":16693710,"url":"https://github.com/cculianu/websocket","last_synced_at":"2025-06-11T12:08:05.141Z","repository":{"id":52900860,"uuid":"256691774","full_name":"cculianu/WebSocket","owner":"cculianu","description":"A lightweight RFC 6455 (Web Socket) implementation for Qt5 \u0026 Qt6 (C++)","archived":false,"fork":false,"pushed_at":"2025-02-13T01:10:30.000Z","size":175,"stargazers_count":30,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T01:44:34.936Z","etag":null,"topics":["cpp","qt","qt5","qwebsocket","rfc6455","websocket","websockets","ws","wss"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cculianu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-18T07:11:50.000Z","updated_at":"2025-02-13T01:10:33.000Z","dependencies_parsed_at":"2025-04-10T01:33:25.612Z","dependency_job_id":"cd8c0454-39c5-4527-9e7a-4e0856e9dd6b","html_url":"https://github.com/cculianu/WebSocket","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cculianu%2FWebSocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cculianu%2FWebSocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cculianu%2FWebSocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cculianu%2FWebSocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cculianu","download_url":"https://codeload.github.com/cculianu/WebSocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cculianu%2FWebSocket/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259262623,"owners_count":22830560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","qt","qt5","qwebsocket","rfc6455","websocket","websockets","ws","wss"],"created_at":"2024-10-12T16:32:07.717Z","updated_at":"2025-06-11T12:08:05.119Z","avatar_url":"https://github.com/cculianu.png","language":"C++","readme":"# Web Socket\n\nA lightweight RFC 6455 (Web Socket) implementation for Qt5 \u0026 Qt6 by Calin Culianu \u003ccalin.culianu@gmail.com\u003e\n\nKey highlights:\n  - Supports both `ws://` and `wss://` Web Sockets.\n  - Support both client-side and server-side mode of operation.\n  - Easy to integrate: just copy `WebSocket.h` and `WebSocket.cpp` into your project\n  - Easy to use with existing codebases:\n    - Unlike the `QWebSocket` module from Qt, this code's main class, `WebSocket::Wrapper` inherits from `QTcpSocket` and thus can easily be integrated into existing code.\n    - In other words, the key paradigm offered is basically a generic wrapper for a regular `QTcpSocket` that itself inherits from `QTcpSocket`.\n  - Asynchronous mode of operation (requires an event loop in the thread the `WebSocket::Wrapper` lives in).\n  - Requires C++17.\n\n### How to use in your project\n\n1. Copy `WebSocket.h` and `WebSocket.cpp` into your project.\n2. Enjoy!  (The license here is MIT so you can use this in any project, commercial or open source).\n\n### Quick Example (Client Side)\nNote that this example is to illustrate how to use `WebSocket::Wrapper`, and some key things have been omitted (such as handling all possible failures and/or cleaning up resources on all possible failure modes, etc).\n\n```c++\n#include \"WebSocket.h\"\n\n// ... and somewhere in your code:\n\n// create the to-be-wrapped socket (this is the real socket)\nQTcpSocket *sock = new QTcpSocket(this);\n\nconnect(sock, \u0026QTcpSocket::connected, this, [this, sock]{\n    // create the socket wrapper\n    auto websock = new WebSocket::Wrapper(sock, this);\n    // 'sock' is now a child of 'websock' ('websock' wraps 'sock').\n    // (do not use 'sock' directly anymore, instead use 'websock').\n\n    // We will start the handshake process below:\n\n    // register the success signal (emitted if the handshake succeeds)\n    connect(websock, \u0026WebSocket::Wrapper::handshakeSuccess, this, [this, websock]{\n       // save the active socket here and use it...\n       // At this point the conneciton is \"speaking\" the web socket protocol\n       // You can call websock-\u003ewrite(), to send.\n       // Use the `messagesReady()` or `readyRead()` signals to receive framed\n       // messages.\n       this-\u003econnectedSock = websock;\n       // use it.... emit a signal here, etc...\n    });\n    // we need to also handle failures\n    connect(websock, \u0026WebSocket::Wrapper::handshakeFailed, this, [this, websock](const QString \u0026 reason){\n        // handle failure, delete the socket, etc\n        qWarning() \u003c\u003c \"WebSocket handshake failed:\" \u003c\u003c reason;\n        // below will also delete child wrapped socket...\n        websock-\u003edeleteLater();\n    });\n    auto res = websock-\u003estartClientHandshake(\"/\", \"somehost.com\");\n    // ^ some time later either handshakeSuccess() or handshakeFailed() will be emitted by 'websock'\n\n    if (!res)\n        // this should not normally happen, but it pays to be careful\n        websock-\u003edeleteLater();\n});\n\nsock-\u003econnectToHost(someHost, somePort);\n\n// be sure to add code to handle connection failures here too (omitted from this example).\n```\n\n### Quick Example (Server Side)\nNote that this example is to illustrate how to use `WebSocket::Wrapper`, and some key things have been omitted (such as handling all possible failures and/or cleaning up resources on all possible failure modes, etc).\n\n```c++\n#include \u003cQTcpServer\u003e\n#include \"WebSocket.h\"\n\n// You must inherit QTcpServer and override incomingConnection(qintptr)\nvoid MyTcpServer::incomingConnection(qintptr socketDescriptor)\n{\n    QTcpSocket *socket = new QTcpSocket(this);\n    socket-\u003esetSocketDescriptor(socketDescriptor);\n    // the below wrapper `ws` becomes parent of the socket,\n    // and `this` is now parent of the wrapper.\n    auto ws = new WebSocket::Wrapper(socket, this);\n\n    // do not access `socket` below this line, use `ws` instead.\n\n    connect(ws, \u0026WebSocket::Wrapper::handshakeSuccess, this, [this, ws] {\n        addPendingConnection(ws);\n        // We must emit newConnection() here because we went asynch and are doing this 'some time later', and the calling code emitted a spurous newConnection() on our behalf previously.. and this is the *real* newConnection()\n        emit newConnection();\n    });\n    // handle handshake failure as well\n    connect(ws, \u0026WebSocket::Wrapper::handshakeFailed, this, [ws](const QString \u0026reason) {\n        qWarning() \u003c\u003c \"WebSocket handshake failed:\" \u003c\u003c  reason;\n        ws-\u003edeleteLater();\n    });\n\n    auto res = ws-\u003estartServerHandshake();\n    // ^ some time later either handshakeSuccess() or handshakeFailed() will be emitted by 'ws'\n\n    if (!res)\n        // this should not normally happen\n        ws-\u003edeleteLater();\n}\n```\n\n### More examples\n\nPlease see the [examples/](examples/) subdiectory for the sample \"TestEchoClientServer\" stand-alone CLI program for testing,\nas well as a user-contributed sample application.  More examples coming soon!\n\nLicense\n----\n\nMIT\n\n### Donations\nYes please!  **Bitcoin** or **Bitcoin Cash** to this address please: **`1Ca1inCimwRhhcpFX84TPRrPQSryTgKW6N`**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcculianu%2Fwebsocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcculianu%2Fwebsocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcculianu%2Fwebsocket/lists"}