[][src]Crate romio

O Romio, Romio, wherefore art thou Romio?
Deny thy father and refuse thy name;
Or if thou wilt not, be but sworn my love
And I'll no longer be so synchronous.

Asynchronous networking bindings for TCP, UDP, and UDS

The types defined in this module are designed to closely follow the APIs of the analogous types in std::net. But rather than implementing synchronous traits like std::io::{Read, Write}, these types implement the asychronous versions provided by the futures-preview crate, i.e. futures::io::{AsyncRead, AsyncWrite}. When using async/await syntax, the experience should be quite similar to traditional blocking code that uses std::net.

Because futures-preview is currently unstable, this crate requires nightly Rust.


TCP Server

#![feature(async_await, await_macro, futures_api)]
use romio::tcp::{TcpListener, TcpStream};
use futures::prelude::*;

async fn say_hello(mut stream: TcpStream) {
    await!(stream.write_all(b"Shall I hear more, or shall I speak at this?"));

async fn listen() -> Result<(), Box<dyn std::error::Error + 'static>> {
    let socket_addr = "".parse()?;
    let mut listener = TcpListener::bind(&socket_addr)?;
    let mut incoming = listener.incoming();

    // accept connections and process them serially
    while let Some(stream) = await!(incoming.next()) {

TCP Client

#![feature(async_await, await_macro, futures_api)]
use std::error::Error;
use futures::prelude::*;
use romio::tcp::{TcpListener, TcpStream};

async fn receive_sonnet() -> Result<(), Box<dyn Error + 'static>> {
    let socket_addr = "".parse()?;
    let mut buffer = vec![];
    let mut stream = await!(TcpStream::connect(&socket_addr))?;

    await!(stream.read(&mut buffer))?;
    println!("{:?}", buffer);



Async TCP bindings.


Async UDP bindings.



A TCP socket server, listening for connections.


A TCP stream between a local and a remote socket.


A UDP socket.