{"id":13611792,"url":"https://github.com/1c3t3a/rust-socketio","last_synced_at":"2025-05-14T09:06:26.859Z","repository":{"id":38186407,"uuid":"325041581","full_name":"1c3t3a/rust-socketio","owner":"1c3t3a","description":"An implementation of a socket.io client written in the Rust programming language.","archived":false,"fork":false,"pushed_at":"2025-02-03T18:50:37.000Z","size":1132,"stargazers_count":450,"open_issues_count":42,"forks_count":83,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-12T21:08:45.544Z","etag":null,"topics":["engine-io","hacktoberfest","rust","socket-io"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/1c3t3a.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"Roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-28T15:01:49.000Z","updated_at":"2025-05-12T16:00:53.000Z","dependencies_parsed_at":"2023-02-12T06:45:22.205Z","dependency_job_id":"1cd859c4-1fba-4c6d-887d-bb23e90a3801","html_url":"https://github.com/1c3t3a/rust-socketio","commit_stats":{"total_commits":585,"total_committers":26,"mean_commits":22.5,"dds":0.5829059829059828,"last_synced_commit":"a4e52873105cc8ed420a5d0a7ddbbd97f50de721"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1c3t3a%2Frust-socketio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1c3t3a%2Frust-socketio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1c3t3a%2Frust-socketio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1c3t3a%2Frust-socketio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1c3t3a","download_url":"https://codeload.github.com/1c3t3a/rust-socketio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110374,"owners_count":22016391,"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":["engine-io","hacktoberfest","rust","socket-io"],"created_at":"2024-08-01T19:02:08.647Z","updated_at":"2025-05-14T09:06:26.838Z","avatar_url":"https://github.com/1c3t3a.png","language":"Rust","funding_links":[],"categories":["Rust","Libraries","库 Libraries"],"sub_categories":["Network programming","网络编程 Network programming"],"readme":"[![Latest Version](https://img.shields.io/crates/v/rust_socketio)](https://crates.io/crates/rust_socketio)\n[![docs.rs](https://docs.rs/rust_socketio/badge.svg)](https://docs.rs/rust_socketio)\n[![Build and code style](https://github.com/1c3t3a/rust-socketio/actions/workflows/build.yml/badge.svg)](https://github.com/1c3t3a/rust-socketio/actions/workflows/build.yml)\n[![Test](https://github.com/1c3t3a/rust-socketio/actions/workflows/test.yml/badge.svg)](https://github.com/1c3t3a/rust-socketio/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/1c3t3a/rust-socketio/branch/main/graph/badge.svg?token=GUF406K0KL)](https://codecov.io/gh/1c3t3a/rust-socketio)\n\n# Rust-socketio-client\n\nAn implementation of a socket.io client written in the rust programming language. This implementation currently supports revision 5 of the socket.io protocol and therefore revision 4 of the engine.io protocol. If you have any connection issues with this client, make sure the server uses at least revision 4 of the engine.io protocol.\nInformation on the [`async`](#async) version can be found below.\n\n## Example usage\n\nAdd the following to your `Cargo.toml` file:\n\n```toml\nrust_socketio = \"*\"\n```\n\nThen you're able to run the following example code:\n\n``` rust\nuse rust_socketio::{ClientBuilder, Payload, RawClient};\nuse serde_json::json;\nuse std::time::Duration;\n\n// define a callback which is called when a payload is received\n// this callback gets the payload as well as an instance of the\n// socket to communicate with the server\nlet callback = |payload: Payload, socket: RawClient| {\n       match payload {\n           Payload::String(str) =\u003e println!(\"Received: {}\", str),\n           Payload::Binary(bin_data) =\u003e println!(\"Received bytes: {:#?}\", bin_data),\n       }\n       socket.emit(\"test\", json!({\"got ack\": true})).expect(\"Server unreachable\")\n};\n\n// get a socket that is connected to the admin namespace\nlet socket = ClientBuilder::new(\"http://localhost:4200\")\n     .namespace(\"/admin\")\n     .on(\"test\", callback)\n     .on(\"error\", |err, _| eprintln!(\"Error: {:#?}\", err))\n     .connect()\n     .expect(\"Connection failed\");\n\n// emit to the \"foo\" event\nlet json_payload = json!({\"token\": 123});\nsocket.emit(\"foo\", json_payload).expect(\"Server unreachable\");\n\n// define a callback, that's executed when the ack got acked\nlet ack_callback = |message: Payload, _| {\n    println!(\"Yehaa! My ack got acked?\");\n    println!(\"Ack data: {:#?}\", message);\n};\n\nlet json_payload = json!({\"myAckData\": 123});\n// emit with an ack\nsocket\n    .emit_with_ack(\"test\", json_payload, Duration::from_secs(2), ack_callback)\n    .expect(\"Server unreachable\");\n\nsocket.disconnect().expect(\"Disconnect failed\")\n\n```\n\nThe main entry point for using this crate is the `ClientBuilder` which provides a way to easily configure a socket in the needed way. When the `connect` method is called on the builder, it returns a connected client which then could be used to emit messages to certain events. One client can only be connected to one namespace. If you need to listen to the messages in different namespaces you need to allocate multiple sockets.\n\n## Documentation\n\nDocumentation of this crate can be found up on [docs.rs](https://docs.rs/rust_socketio).\n\n## Current features\n\nThis implementation now supports all of the features of the socket.io protocol mentioned [here](https://github.com/socketio/socket.io-protocol).\nIt generally tries to make use of websockets as often as possible. This means most times\nonly the opening request uses http and as soon as the server mentions that he is able to upgrade to\nwebsockets, an upgrade  is performed. But if this upgrade is not successful or the server\ndoes not mention an upgrade possibility, http-long polling is used (as specified in the protocol specs).\nHere's an overview of possible use-cases:\n- connecting to a server.\n- register callbacks for the following event types:\n    - open\n    - close\n    - error\n    - message\n    - custom events like \"foo\", \"on_payment\", etc.\n- send JSON data to the server (via `serde_json` which provides safe\nhandling).\n- send JSON data to the server and receive an `ack`.\n- send and handle Binary data.\n\n## \u003ca name=\"async\"\u003e Async version\nThis library provides an ability for being executed in an asynchronous context using `tokio` as\nthe execution runtime.\nPlease note that the current async implementation is still experimental, the interface can be object to\nchanges at any time.\nThe async `Client` and `ClientBuilder` support a similar interface to the sync version and live\nin the `asynchronous` module. In order to enable the support, you need to enable the `async`\nfeature flag:\n```toml\nrust_socketio = { version = \"*\", features = [\"async\"] }\n```\n\nThe following code shows the example above in async fashion:\n``` rust\nuse futures_util::FutureExt;\nuse rust_socketio::{\n    asynchronous::{Client, ClientBuilder},\n    Payload,\n};\nuse serde_json::json;\nuse std::time::Duration;\n\n#[tokio::main]\nasync fn main() {\n    // define a callback which is called when a payload is received\n    // this callback gets the payload as well as an instance of the\n    // socket to communicate with the server\n    let callback = |payload: Payload, socket: Client| {\n        async move {\n            match payload {\n                Payload::String(str) =\u003e println!(\"Received: {}\", str),\n                Payload::Binary(bin_data) =\u003e println!(\"Received bytes: {:#?}\", bin_data),\n            }\n            socket\n                .emit(\"test\", json!({\"got ack\": true}))\n                .await\n                .expect(\"Server unreachable\");\n        }\n        .boxed()\n    };\n\n    // get a socket that is connected to the admin namespace\n    let socket = ClientBuilder::new(\"http://localhost:4200/\")\n        .namespace(\"/admin\")\n        .on(\"test\", callback)\n        .on(\"error\", |err, _| {\n            async move { eprintln!(\"Error: {:#?}\", err) }.boxed()\n        })\n        .connect()\n        .await\n        .expect(\"Connection failed\");\n\n    // emit to the \"foo\" event\n    let json_payload = json!({\"token\": 123});\n    socket\n        .emit(\"foo\", json_payload)\n        .await\n        .expect(\"Server unreachable\");\n\n    // define a callback, that's executed when the ack got acked\n    let ack_callback = |message: Payload, _: Client| {\n        async move {\n            println!(\"Yehaa! My ack got acked?\");\n            println!(\"Ack data: {:#?}\", message);\n        }\n        .boxed()\n    };\n\n    let json_payload = json!({\"myAckData\": 123});\n    // emit with an ack\n    socket\n        .emit_with_ack(\"test\", json_payload, Duration::from_secs(2), ack_callback)\n        .await\n        .expect(\"Server unreachable\");\n\n    socket.disconnect().await.expect(\"Disconnect failed\");\n}\n```\n\n## Content of this repository\n\nThis repository contains a rust implementation of the socket.io protocol as well as the underlying engine.io protocol.\n\nThe details about the engine.io protocol can be found here:\n\n* \u003chttps://github.com/socketio/engine.io-protocol\u003e\n\nThe specification for the socket.io protocol here:\n\n* \u003chttps://github.com/socketio/socket.io-protocol\u003e\n\nLooking at the component chart, the following parts are implemented (Source: https://socket.io/images/dependencies.jpg):\n\n\u003cimg src=\"docs/res/dependencies.jpg\" width=\"50%\"/\u003e\n\n## Licence\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1c3t3a%2Frust-socketio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1c3t3a%2Frust-socketio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1c3t3a%2Frust-socketio/lists"}