{"id":24609627,"url":"https://github.com/tony-artz/swss","last_synced_at":"2025-03-18T12:33:24.538Z","repository":{"id":273822776,"uuid":"920726531","full_name":"Tony-ArtZ/swss","owner":"Tony-ArtZ","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-23T06:24:59.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T07:26:19.983Z","etag":null,"topics":["c","clang","libraries","library","socket-programming","websocket"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tony-ArtZ.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-01-22T17:07:19.000Z","updated_at":"2025-01-23T06:26:18.000Z","dependencies_parsed_at":"2025-01-23T07:36:23.769Z","dependency_job_id":null,"html_url":"https://github.com/Tony-ArtZ/swss","commit_stats":null,"previous_names":["tony-artz/swss"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony-ArtZ%2Fswss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony-ArtZ%2Fswss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony-ArtZ%2Fswss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tony-ArtZ%2Fswss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tony-ArtZ","download_url":"https://codeload.github.com/Tony-ArtZ/swss/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244223144,"owners_count":20418680,"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","clang","libraries","library","socket-programming","websocket"],"created_at":"2025-01-24T18:15:36.548Z","updated_at":"2025-03-18T12:33:24.520Z","avatar_url":"https://github.com/Tony-ArtZ.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SWSS (Simple WebSocket Server Library)\n\nA lightweight, high-performance WebSocket server implementation in C, fully compliant with RFC 6455. Built on Linux sockets with support for multi-threaded connections and message fragmentation.\n\n## Features\n\n- **Full RFC 6455 Compliance**: Implements the WebSocket protocol as specified in [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455)\n- **Frame Types Support**:\n  - Text frames (0x1)\n  - Binary frames (0x2)\n  - Close frames (0x8)\n  - Ping frames (0x9)\n  - Pong frames (0xA)\n  - Continuation frames (0x0)\n- **Robust Frame Handling**:\n  - Handles fragmented messages\n  - Supports both masked and unmasked frames\n  - Handles variable payload lengths (7-bit, 16-bit, and 64-bit lengths)\n- **Event-Driven Architecture**:\n  - Connection open/close events\n  - Message reception events\n  - Error handling events\n- **Thread-Safe**: Each client connection runs in its own thread\n- **Zero Dependencies**: Only requires standard C libraries\n\n## Installation\n\n```bash\n# Clone the repository\ngit clone https://github.com/yourusername/swss-lib.git\ncd swss-lib\n\n# Build the library\nmake\n\n# Install (requires root privileges)\nsudo make install\n\n# Link the shared libraries\nsudo ldconfig\n```\n\n## Project Structure\n\n```\nswss-lib/\n├── include/\n│   ├── swss.h       # Main header file\n│   ├── utils.h      # Utility functions\n│   └── base64.h     # Base64 encoding\n├── src/\n│   ├── swss.c       # Core WebSocket implementation\n│   ├── utils.c      # Utility implementations\n│   └── base64.c     # Base64 encoding implementation\n├── example/\n│   └── main.c       # Example chat server\n├── Makefile\n└── README.md\n```\n\n## Usage Example\n\n```c\n#include \u003cswss/swss.h\u003e\n\n// Callback when client connects\nvoid on_open(int client_fd) {\n    printf(\"Client %d connected\\n\", client_fd);\n}\n\n// Callback when message is received\nvoid on_message(int client_fd, const char *message, size_t length) {\n    printf(\"Received message from client %d: %.*s\\n\", client_fd, (int)length, message);\n    // Echo back to client\n    ws_send_txt(client_fd, message, length);\n}\n\n// Callback when client disconnects\nvoid on_close(int client_fd) {\n    printf(\"Client %d disconnected\\n\", client_fd);\n}\n\n// Error handling callback\nvoid on_error(int client_fd, int error_code) {\n    printf(\"Error %d on client %d\\n\", error_code, client_fd);\n}\n\nint main() {\n    // Initialize callback structure\n    ws_callbacks_t callbacks = {\n        .on_open = on_open,\n        .on_message = on_message,\n        .on_close = on_close,\n        .on_error = on_error\n    };\n\n    // Initialize WebSocket server\n    ws_init(\u0026callbacks);\n\n    // Start listening on port 8080\n    ws_listen(\"8080\");\n    return 0;\n}\n```\n\n## Building Your Application\n\n```bash\ngcc -o myapp myapp.c -lswss -lpthread\n```\n\n## Multi-Frame Support\n\nThe library handles message fragmentation automatically, allowing for:\n- Large message transmission\n- Streaming data\n- Real-time updates\n- Memory-efficient processing of large payloads\n\nExample of how fragmentation works internally:\n1. Messages larger than 65535 bytes are automatically fragmented\n2. Continuation frames are properly tracked and assembled\n3. Final message is delivered only when the FIN bit is received\n4. Memory is managed efficiently during reassembly\n\n### WebSocket Frame Structure\n\nThe implementation handles WebSocket frames according to RFC 6455 specification:\n\n```\n 0                   1                   2                   3\n 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n+-+-+-+-+-------+-+-------------+-------------------------------+\n|F|R|R|R| opcode|M| Payload len |    Extended payload length    |\n|I|S|S|S|  (4)  |A|     (7)    |             (16/64)          |\n|N|V|V|V|       |S|             |   (if payload len==126/127)   |\n| |1|2|3|       |K|             |                               |\n+-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +\n|     Extended payload length continued, if payload len == 127  |\n+ - - - - - - - - - - - - - - - +-------------------------------+\n|                               |Masking-key, if MASK set to 1  |\n+-------------------------------+-------------------------------+\n| Masking-key (continued)       |          Payload Data        |\n+-------------------------------- - - - - - - - - - - - - - - - +\n:                     Payload Data continued ...                :\n+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +\n|                     Payload Data continued ...                |\n+---------------------------------------------------------------+\n```\n\n\n## Thread Safety\n\nThe library is designed to be thread-safe:\n- Each client connection runs in its own thread\n- Global state is properly protected\n- Callback functions are executed in the client's thread context\n- Resources are automatically cleaned up on disconnection\n\n## Limitations\n\n- Currently supports Linux platforms only\n- Maximum concurrent connections limited by system resources\n- WebSocket client implementation not included\n\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n\n```\n  /$$$$$$$ /$$  /$$  /$$  /$$$$$$$ /$$$$$$$\n /$$_____/| $$ | $$ | $$ /$$_____//$$_____/\n|  $$$$$$ | $$ | $$ | $$|  $$$$$$|  $$$$$$ \n \\____  $$| $$ | $$ | $$ \\____  $$\\____  $$\n /$$$$$$$/|  $$$$$/$$$$/ /$$$$$$$//$$$$$$$/\n|_______/  \\_____/\\___/ |_______/|_______/ \n\n ```                         \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftony-artz%2Fswss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftony-artz%2Fswss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftony-artz%2Fswss/lists"}