๐Ÿ“ฆ 1c3t3a / rust-socketio

An implementation of a socket.io client written in the Rust programming language.

โ˜… 470 stars โ‘‚ 99 forks ๐Ÿ‘ 470 watching โš–๏ธ MIT License
engine-iohacktoberfestrustsocket-io
๐Ÿ“ฅ Clone https://github.com/1c3t3a/rust-socketio.git
HTTPS git clone https://github.com/1c3t3a/rust-socketio.git
SSH git clone git@github.com:1c3t3a/rust-socketio.git
CLI gh repo clone 1c3t3a/rust-socketio
Bastian Kersting Bastian Kersting ci: Fix coverage.yml a4e5287 1 years ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .devcontainer
๐Ÿ“ .github
๐Ÿ“ ci
๐Ÿ“ docs
๐Ÿ“ engineio
๐Ÿ“ socketio
๐Ÿ“„ .gitignore
๐Ÿ“„ Cargo.lock
๐Ÿ“„ Cargo.toml
๐Ÿ“„ CHANGELOG.md
๐Ÿ“„ codecov.yml
๐Ÿ“„ CONTRIBUTING.md
๐Ÿ“„ LICENSE
๐Ÿ“„ Makefile
๐Ÿ“„ README.md
๐Ÿ“„ Roadmap.md
๐Ÿ“„ README.md

Latest Version docs.rs Build and code style Test codecov

Rust-socketio-client

An 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. Information on the async version can be found below.

Example usage

Add the following to your Cargo.toml file:

rust_socketio = "*"

Then you're able to run the following example code:

`` rust use rust_socketio::{ClientBuilder, Payload, RawClient}; use serde_json::json; use std::time::Duration; // define a callback which is called when a payload is received // this callback gets the payload as well as an instance of the // socket to communicate with the server let callback = |payload: Payload, socket: RawClient| { match payload { Payload::String(str) => println!("Received: {}", str), Payload::Binary(bin_data) => println!("Received bytes: {:#?}", bin_data), } socket.emit("test", json!({"got ack": true})).expect("Server unreachable") }; // get a socket that is connected to the admin namespace let socket = ClientBuilder::new("http://localhost:4200") .namespace("/admin") .on("test", callback) .on("error", |err, _| eprintln!("Error: {:#?}", err)) .connect() .expect("Connection failed"); // emit to the "foo" event let json_payload = json!({"token": 123}); socket.emit("foo", json_payload).expect("Server unreachable"); // define a callback, that's executed when the ack got acked let ack_callback = |message: Payload, _| { println!("Yehaa! My ack got acked?"); println!("Ack data: {:#?}", message); }; let json_payload = json!({"myAckData": 123}); // emit with an ack socket .emit_with_ack("test", json_payload, Duration::from_secs(2), ack_callback) .expect("Server unreachable"); socket.disconnect().expect("Disconnect failed") %%CODEBLOCK1%%toml rust_socketio = { version = "*", features = ["async"] } %%CODEBLOCK2%% rust use futures_util::FutureExt; use rust_socketio::{ asynchronous::{Client, ClientBuilder}, Payload, }; use serde_json::json; use std::time::Duration; #[tokio::main] async fn main() { // define a callback which is called when a payload is received // this callback gets the payload as well as an instance of the // socket to communicate with the server let callback = |payload: Payload, socket: Client| { async move { match payload { Payload::String(str) => println!("Received: {}", str), Payload::Binary(bin_data) => println!("Received bytes: {:#?}", bin_data), } socket .emit("test", json!({"got ack": true})) .await .expect("Server unreachable"); } .boxed() }; // get a socket that is connected to the admin namespace let socket = ClientBuilder::new("http://localhost:4200/") .namespace("/admin") .on("test", callback) .on("error", |err, _| { async move { eprintln!("Error: {:#?}", err) }.boxed() }) .connect() .await .expect("Connection failed"); // emit to the "foo" event let json_payload = json!({"token": 123}); socket .emit("foo", json_payload) .await .expect("Server unreachable"); // define a callback, that's executed when the ack got acked let ack_callback = |message: Payload, _: Client| { async move { println!("Yehaa! My ack got acked?"); println!("Ack data: {:#?}", message); } .boxed() }; let json_payload = json!({"myAckData": 123}); // emit with an ack socket .emit_with_ack("test", json_payload, Duration::from_secs(2), ack_callback) .await .expect("Server unreachable"); socket.disconnect().await.expect("Disconnect failed"); } ``

Content of this repository

This repository contains a rust implementation of the socket.io protocol as well as the underlying engine.io protocol.

The details about the engine.io protocol can be found here:

The specification for the socket.io protocol here:

Looking at the component chart, the following parts are implemented (Source: https://socket.io/images/dependencies.jpg):

Licence

MIT