{"id":19156908,"url":"https://github.com/bertrandmartel/websocket-non-blocking","last_synced_at":"2025-05-07T07:46:48.281Z","repository":{"id":32055986,"uuid":"35627703","full_name":"bertrandmartel/websocket-non-blocking","owner":"bertrandmartel","description":"C++ websocket non-blocking server library for Qt4/Qt5","archived":false,"fork":false,"pushed_at":"2017-01-11T19:29:02.000Z","size":2337,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-19T20:17:33.653Z","etag":null,"topics":["cpp-library","qt","websocket","websocket-server"],"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/bertrandmartel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-14T18:08:03.000Z","updated_at":"2023-06-29T02:43:42.000Z","dependencies_parsed_at":"2022-09-10T23:11:14.808Z","dependency_job_id":null,"html_url":"https://github.com/bertrandmartel/websocket-non-blocking","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fwebsocket-non-blocking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fwebsocket-non-blocking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fwebsocket-non-blocking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bertrandmartel%2Fwebsocket-non-blocking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bertrandmartel","download_url":"https://codeload.github.com/bertrandmartel/websocket-non-blocking/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252838778,"owners_count":21812082,"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-library","qt","websocket","websocket-server"],"created_at":"2024-11-09T08:36:22.638Z","updated_at":"2025-05-07T07:46:48.244Z","avatar_url":"https://github.com/bertrandmartel.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Websocket non-blocking server library\n\n[![Build Status](https://travis-ci.org/akinaru/websocket-non-blocking.svg?branch=master)](https://travis-ci.org/akinaru/websocket-non-blocking)\n[![License](http://img.shields.io/:license-mit-blue.svg)](LICENSE.md)\n\nhttp://akinaru.github.io/websocket-non-blocking/\n\nC++ websocket non-blocking server library for Qt4/Qt5\n\n## Usage\n\nStart websocket server :\n```\nWebsocketServer server;\n\nbool success = server.listen(QHostAddress(\"127.0.0.1\"), 8443);\n```\n\nStop websocket server :\n```\nserver.close();\n```\n\n## Integrate in your project\n\n* from git submodule\n\n```\ngit submodule add git://github.com/akinaru/websocket-non-blocking.git\n```\n\nand in your `project.pro` :\n\n```\nTEMPLATE = subdirs\nSUBDIRS = websocket-non-blocking your-app\nyour-app.depends = websocket-non-blocking\n```\n\nwith in `your-app.pro` :\n\n```\nTARGET = your-app\nSOURCES = main.cpp\nINCLUDEPATH += $$PWD/../websocket-non-blocking/libwebsocket/release\nLIBS += -L$$PWD/../websocket-non-blocking/libwebsocket/release -lwebsocket\nDEPENDPATH += $$PWD/../websocket-non-blocking/libwebsocket/release\n```\n\n## Monitor clients\n\nBuild your own client monitoring class that inherits `IClientEventListener` : \n\n```\nclass ClientSocketHandler :  public IClientEventListener\n{\npublic:\n\n    ClientSocketHandler();\n\n    ~ClientSocketHandler();\n\n    void onClientClose(IWebsocketClient \u0026client);\n\n    void onClientConnection(IWebsocketClient \u0026client);\n\n    void onMessageReceivedFromClient(IWebsocketClient \u0026client, std::string message);\n};\n```\n\nAdd listener to server instance : \n\n```\n#include \"ClientSockethandler.h\"\n\n....\n\nClientSocketHandler *clientHandler = new ClientSocketHandler();\n\nserver.addClientEventListener(clientHandler);\n```\n\nIn this `ClientSocketHandler` you have 3 callbacks that will notify you on client connection change and arrival of client messages :\n\n* `void onClientClose(IWebsocketClient \u0026client);` notify when client socket close\n* `void onClientConnection(IWebsocketClient \u0026client);` notify when client socket connect to server\n* `void onMessageReceivedFromClient(IWebsocketClient \u0026client,std::string message);` notify when a socket client send a message to you\n\nYou can send a message back with `IWebsocketClient` sent from the same callback with `sendMessage(std::string textToSend)` method :\n\n```\nvoid ClientSocketHandler::onMessageReceivedFromClient(IWebsocketClient \u0026client,string message)\n{\n    cout \u003c\u003c \"Client socket message received : \" \u003c\u003c message.data() \u003c\u003c endl;\n\n    client.sendMessage(\"OK I received your message !\");\n}\n```\n\nCheck the client monitoring example [here](./libwebsocket-test/ClientSocketHandler.cpp)\n\n## SSL secured websocket server\n\n```\nWebsocketServer server;\n\nserver.setSSL(true); // set SSL to true (default is false)\n```\n\nThen you set your public/private/ca certificates separately with respective methods : \n\n```\nserver.setPublicCert(SslHandler::retrieveCertFromFile(PUBLIC_CERT));\nserver.setPrivateCert(SslHandler::retrieveKeyCertFile(PRIVATE_CERT,PRIVATE_CERT_PASS));\nserver.setCaCert(SslHandler::retrieveveCaCertListFromFile(CA_CERTS));\n```\n\nYou can use static method from [`SslHandler`](./libwebsocket-test/SslHandler.cpp) :\n\n* public cert must be a QSslCertificate : `SslHandler::retrieveCertFromFile(char * filepath)`\n* private cert must be a QSslKey : `SslHandler::retrieveKeyCertFile(char * filepath,char * passKey)`\n* CA cert must be a QList of QSslCertificate : `SslHandler::retrieveveCaCertListFromFile(char * filepath)`\n\nEventually add event listener as described above and start websocket server : \n\n```\nserver.addClientEventListener(clientHandler);\n\nbool success = server.listen(QHostAddress(\"127.0.0.1\"), 8443);\n```\n\n## Troubleshooting SSL errors with local browser JS client\n\n\u003eBad certificate | Unknown CA errors\n\nThis could mean you didn't import your not-trusted-CA certificate into your browser.\n\n\u003eThe remote host closed the connection\n\nJust load your URL with \"https\" : https://127.0.0.1:8443 . Browser will prompt you to accept the certificates and it will probably solve your connection error.\n\n\n## Debugging SSL connection error\n\nuse openssl command line tool to debug ssl connection : \n\n```\nopenssl s_client -connect 127.0.0.1:8443\n```\n\n## Server-Client key/cert generation\n\nSample certs are in [libwesocket-test/certs](./libwesocket-test/certs) folder, you will find server,client and ca cert build with easy-rsa :\n\nhttps://github.com/OpenVPN/easy-rsa\n\nWith last release of easy-rsa, you can build your own key with the following : \n\n* `./build-ca` : generate a new CA for you\n* `./build-server-full myServer` : will build for you public cert and private cert signed with CA for server\n* `./build-client-full myClient` : will build for you public cert and private cert signed with CA for client\n\n## Build library \u0026 examples\n\n```\nqmake\nmake\n```\n\n## Run examples\n\nOpen a websocket on port 8443 :\n\n```\n./libwebsocket-test/release/libwebsocket-test 127.0.0.1 8443\n```\n\nOpen Javascript clients located in [client-test/js](./client-test/js) :\n\n\u003chr/\u003e\n\n![client side](./img/clientSide.png)\n\n\u003chr/\u003e\n\n![server side](./img//serverSide.png)\n\n## Valgrind checking\n\n```\ncd libwebsocket-test/release\n\nvalgrind --tool=memcheck --leak-check=full --suppressions=../../memcheck.suppress ./libwebsocket-test \u003cip\u003e \u003cport\u003e\n\n```\n\n## Compatibility\n\n* Qt4\n* Qt5\n\n## Specification\n\n* https://tools.ietf.org/html/rfc6455","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbertrandmartel%2Fwebsocket-non-blocking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbertrandmartel%2Fwebsocket-non-blocking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbertrandmartel%2Fwebsocket-non-blocking/lists"}