Skip to content

rsocket/rsocket-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rsocket-rust

Crates.io Crates.io License GitHub Release

rsocket-rust is an implementation of the RSocket protocol in Rust(1.39+). It's an alpha version and still under active development.
Do not use it in a production environment!

Example

Here are some example codes which show how RSocket works in Rust.

Server

extern crate rsocket_rust;
extern crate tokio;
#[macro_use]
extern crate log;
use rsocket_rust::prelude::*;
use std::env;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    env_logger::builder().init();
    let addr = env::args().nth(1).unwrap_or("tcp://127.0.0.1:7878".to_string());

    RSocketFactory::receive()
        .transport(&addr)
        .acceptor(|setup, _socket| {
            info!("accept setup: {:?}", setup);
            Ok(Box::new(EchoRSocket))
            // Or you can reject setup
            // Err(From::from("SETUP_NOT_ALLOW"))
        })
        .serve()
        .await
}

Client

extern crate rsocket_rust;

use rsocket_rust::prelude::*;

#[tokio::main]
#[test]
async fn test() {
    let cli = RSocketFactory::connect()
        .acceptor(|| Box::new(EchoRSocket))
        .transport("tcp://127.0.0.1:7878")
        .setup(Payload::from("READY!"))
        .mime_type("text/plain", "text/plain")
        .start()
        .await
        .unwrap();
    let req = Payload::builder()
        .set_data_utf8("Hello World!")
        .set_metadata_utf8("Rust")
        .build();
    let res = cli.request_response(req).await.unwrap();
    println!("got: {:?}", res);
    cli.close();
}

Dependencies

TODO

  • Operations
    • METADATA_PUSH
    • REQUEST_FNF
    • REQUEST_RESPONSE
    • REQUEST_STREAM
    • REQUEST_CHANNEL
  • More Operations
    • Error
    • Cancel
    • Fragmentation
    • Resume
  • QoS
    • RequestN
    • Lease
  • Transport
    • TCP
    • Websocket
  • Reactor
    • ...
  • High Level APIs
    • Client
    • Server

About

RSocket Rust Implementation using Tokio

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published