Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 7 days ago
JSON representation

A Rust Websocket client that compiles to both native and web

Awesome Lists containing this project

README

        

# ewebsock

[github](https://github.com/rerun-io/ewebsock)
[![Latest version](https://img.shields.io/crates/v/ewebsock.svg)](https://crates.io/crates/ewebsock)
[![Documentation](https://docs.rs/ewebsock/badge.svg)](https://docs.rs/ewebsock)
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
[![Build Status](https://github.com/rerun-io/ewebsock/workflows/CI/badge.svg)](https://github.com/rerun-io/ewebsock/actions?workflow=CI)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

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)
```