{"id":15099194,"url":"https://github.com/lakshagg/cwebsockets","last_synced_at":"2026-01-07T02:10:48.729Z","repository":{"id":187687792,"uuid":"677243911","full_name":"LakshAgg/CWebSockets","owner":"LakshAgg","description":"A simple implementation of web socket client in c using libcurl.","archived":false,"fork":false,"pushed_at":"2023-08-13T09:42:30.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T17:45:28.287Z","etag":null,"topics":["c","curl","cwebsockets","libcurl","libcurl-websockets","libcurl-wss","websocket","websocket-library","websockets","websockets-client","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/LakshAgg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-08-11T04:58:18.000Z","updated_at":"2024-03-26T07:54:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"dc630b06-b74c-4c79-a954-7824b3964410","html_url":"https://github.com/LakshAgg/CWebSockets","commit_stats":{"total_commits":7,"total_committers":1,"mean_commits":7.0,"dds":0.0,"last_synced_commit":"bab7507d1806a9caa3e1eb2c6691ebfe6201cbbc"},"previous_names":["lakshagg/cwebsockets"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LakshAgg%2FCWebSockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LakshAgg%2FCWebSockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LakshAgg%2FCWebSockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LakshAgg%2FCWebSockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LakshAgg","download_url":"https://codeload.github.com/LakshAgg/CWebSockets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236699575,"owners_count":19190840,"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":["c","curl","cwebsockets","libcurl","libcurl-websockets","libcurl-wss","websocket","websocket-library","websockets","websockets-client","ws","wss"],"created_at":"2024-09-25T17:07:24.593Z","updated_at":"2026-01-07T02:10:43.710Z","avatar_url":"https://github.com/LakshAgg.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CWebSockets\nA simple implementation of web socket client in c using libcurl. *Note: requires libcurl version \u003e= 7.86.0 with wss enabled*\n\nThis library contains the implementation of WebSocket client operations, including connecting to a WebSocket server, sending and receiving data, managing client connections, and handling callbacks for open, close, and message events.\n\n## Installation\n*Make sure libcurl version \u003e= 7.86.0 is installed. with wss enabled*\n\nTo enable wss with libcurl you have to build it yourself from source. \nOr just execute `source install_curl.sh` *on linux* (tested with debian), which will take a while and install libcurl with WebSocket enabled.\n\nTo install this library execute the following commands:\n```sh\ngit clone https://github.com/LakshAgg/CWebSockets.git\ncd CWebSockets\n\nmake\nsudo make install\nmake clean\n```\n\nTo uninstall execute `make uninstall`.\n\nCompile with `-lcwebsockets -lcurl`.\n\n## Example\nCheck out the [example](example.c) program which uses the Binance market stream and prints the latest trades for 10 seconds.\n\n## WSS_Client\n```c\nstruct WSS_Client\n{\n    /// @brief Called on successfully connecting to the socket (optional)\n    void (*on_open)(struct WSS_Client *client);\n\n    /// @brief Called after socket gets closed (optional)\n    void (*on_close)(struct WSS_Client *client);\n\n    /// @brief Called on recieving a message\n    void (*on_message)(struct WSS_Client *client, void *data, unsigned long len);\n\n    /// @brief The web socket stream url: begins with ws or wss\n    char *url;\n}\n```\n#### url\nThe URL to connect to. eg: `wss://fstream.binance.com/ws/`.\n\n#### on_open(WSS_Client *client)\nThis function will be called *after* the client has successfully connected by calling `start_wss_client` or `connect_wss_client`.\n\n#### on_message(WSS_Client *client, void *data, unsigned long len)\nThis function is called when a message is received from the socket.\n\nThe data received is not null-terminated.\n`len` is the length of data received.\n\n#### on_close(WSS_Client *client)\nThis function will be *after* the client has disconnected from the socket.\n\n## Functions \n### connect_wss_client\n```c\n/**\n * @brief Just connects to the web socket.\n * @param client\n * @return int - 0 if success\n */\nint connect_wss_client(WSS_Client *client);\n```\nThis function will open a new connection and call client-\u003eon_open if successful. After you are done with the connection, call `close_wss_client`. At the end of the program call `curl_global_cleanup` to avoid any memory leaks.\n\n### listen_wss_client\n```c\n/**\n * @brief Create a new thread if not done already to read from sockets.\n * @param client\n * @return int - 0 if success\n */\nint listen_wss_client(WSS_Client *client);\n```\nA list of all open connections is maintained by CWebSockets, this is used with `poll` to wait for any new data in any connection.\n\nIf `listen_wss_client` is called for the first time, it will create a new thread using `pthread_create` which will use `poll` to wait for any data. On subsequent calls, only the list is updated to include the new client's socket.\n\n### send_wss_client\n```c\n/**\n * @brief Sends the data through the socket.\n * @param client\n * @param data\n * @param size\n * @param flags - for curl_ws_send\n * @return int - 0 if success\n */\nint send_wss_client(WSS_Client *client, void *data, unsigned long size, unsigned int flags);\n```\nThis function sends the data and returns 0 on success. For more info on flags, refer to [curl_ws_send](https://curl.se/libcurl/c/curl_ws_send.html).\n\n### close_wss_client\n```c\n/**\n * @brief Closes the connection\n * @param client\n */\nvoid close_wss_client(WSS_Client *client);\n```\nThis closes the connection and frees the memory allocated for it.\n\n### start_wss_client\n```c\n/**\n * @brief Connects to the socket and starts listening\n * @param client\n * @return int\n */\nint start_wss_client(WSS_Client *client);\n```\nThis function just calls connect and listen together and returns 0 if no error occurs.\n\n### join_thread_wss_client\nThis function joins the thread created for reading new data. This will block further execution.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flakshagg%2Fcwebsockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flakshagg%2Fcwebsockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flakshagg%2Fcwebsockets/lists"}