Skip to content

mooncell07/mayuri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mayuri

A WIP Asynchronous WebSocket Client Library.

Installation

Install the mayuri crate from crates-io.

Usage

use async_trait::async_trait;
use mayuri::{Context, Transport, WebSocket, WebSocketProtocol};
use tokio;

pub struct App {}

#[async_trait]
impl WebSocketProtocol for App {
    async fn on_connect(&mut self, mut transport: Transport) {
        println!("Connected!");
        transport.write_text(b"hello!").await.unwrap();
    }

    async fn on_message(&mut self, ctx: Context) {
        let msg = ctx.read_text();
        println!("Received: {}", msg);
    }

    async fn on_close(&mut self, _: Context) {
        println!("Closed by the Peer!");
    }
}

#[tokio::main]
async fn main() {
    let mut ws = WebSocket::connect("wss://ws.ifelse.io", App {})
        .await
        .unwrap();
    ws.run().await.unwrap();
}

Find more in examples.

About

Asynchronous WebSocket Client Library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages