https://github.com/rerun-io/ewebsock
A Rust Websocket client that compiles to both native and web
https://github.com/rerun-io/ewebsock
rust websocket
Last synced: 19 days ago
JSON representation
A Rust Websocket client that compiles to both native and web
- Host: GitHub
- URL: https://github.com/rerun-io/ewebsock
- Owner: rerun-io
- License: apache-2.0
- Created: 2022-02-23T10:41:54.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-11T15:42:52.000Z (6 months ago)
- Last Synced: 2025-04-06T22:02:59.306Z (26 days ago)
- Topics: rust, websocket
- Language: Rust
- Homepage:
- Size: 4.1 MB
- Stars: 245
- Watchers: 2
- Forks: 32
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ewebsock
[
](https://github.com/rerun-io/ewebsock)
[](https://crates.io/crates/ewebsock)
[](https://docs.rs/ewebsock)
[](https://github.com/rust-secure-code/safety-dance/)
[](https://github.com/rerun-io/ewebsock/actions?workflow=CI)

This is a simple [WebSocket](https://en.wikipedia.org/wiki/WebSocket) library for Rust which can be compiled to both native and web (WASM).
## Usage
``` rust
let options = ewebsock::Options::default();
// see documentation for more options
let (mut sender, receiver) = ewebsock::connect("ws://example.com", options).unwrap();
sender.send(ewebsock::WsMessage::Text("Hello!".into()));
while let Some(event) = receiver.try_recv() {
println!("Received {:?}", event);
}
```## Testing
First start the example echo server with:
```sh
cargo r -p echo_server
```Then test the library with:
```sh
# native mode
cargo run -p example_app# web mode
# install trunk with `cargo install trunk` - https://trunkrs.dev/
(cd example_app && trunk serve)
```