#enforce

rust_engineio

An implementation of a engineio client written in rust

12 unstable releases (3 breaking)

0.6.0 Apr 16, 2024
0.5.0 Mar 31, 2024
0.4.4 Nov 18, 2023
0.4.3 Jul 8, 2023
0.3.0-alpha.2 Oct 14, 2021

#92 in WebSocket

Download history 2433/week @ 2024-06-16 2393/week @ 2024-06-23 2614/week @ 2024-06-30 3135/week @ 2024-07-07 3043/week @ 2024-07-14 2981/week @ 2024-07-21 3018/week @ 2024-07-28 3241/week @ 2024-08-04 2814/week @ 2024-08-11 2695/week @ 2024-08-18 3467/week @ 2024-08-25 2245/week @ 2024-09-01 2488/week @ 2024-09-08 2949/week @ 2024-09-15 3182/week @ 2024-09-22 3540/week @ 2024-09-29

12,241 downloads per month
Used in 12 crates (2 directly)

MIT license

140KB
3.5K SLoC

Latest Version docs.rs

Rust-engineio-client

An implementation of a engine.io client written in the rust programming language. This implementation currently supports 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.

Example usage

use rust_engineio::{ClientBuilder, Client, packet::{Packet, PacketId}};
use url::Url;
use bytes::Bytes;

// get a client with an `on_open` callback
let client: Client = ClientBuilder::new(Url::parse("http://localhost:4201").unwrap())
     .on_open(|_| println!("Connection opened!"))
     .build()
     .expect("Connection failed");

// connect to the server
client.connect().expect("Connection failed");

// create a packet, in this case a message packet and emit it
let packet = Packet::new(PacketId::Message, Bytes::from_static(b"Hello World"));
client.emit(packet).expect("Server unreachable");

// disconnect from the server
client.disconnect().expect("Disconnect failed")

The main entry point for using this crate is the ClientBuilder (or asynchronous::ClientBuilder respectively) which provides the opportunity to define how you want to connect to a certain endpoint. The following connection methods are available:

  • build: Build websocket if allowed, if not fall back to polling. Standard configuration.
  • build_polling: enforces a polling transport.
  • build_websocket_with_upgrade: Build socket with a polling transport then upgrade to websocket transport (if possible).
  • build_websocket: Build socket with only a websocket transport, crashes when websockets are not allowed.

Current features

This implementation now supports all of the features of the engine.io protocol mentioned here. This includes various transport options, the possibility of sending engine.io packets and registering the common engine.io event callbacks:

  • on_open
  • on_close
  • on_data
  • on_error
  • on_packet

It is also possible to pass in custom tls configurations via the TlsConnector as well as custom headers for the opening request.

Documentation

Documentation of this crate can be found up on docs.rs.

Async version

The crate also ships with an asynchronous version that can be enabled with a feature flag. The async version implements the same features mentioned above. The asynchronous version has a similar API, just with async functions. Currently the futures can only be executed with tokio. In the first benchmarks the async version showed improvements of up to 93% in speed. To make use of the async version, import the crate as follows:

[depencencies]
rust-engineio = { version = "0.3.1", features = ["async"] }

Dependencies

~6–19MB
~294K SLoC