rustic-io

Crates.iorustic-io
lib.rsrustic-io
version0.2.9
sourcesrc
created_at2014-12-04 14:34:31.956037
updated_at2015-12-11 23:56:40.231265
descriptionWebsocket server library for event based messaging
homepage
repositoryhttps://github.com/nathansizemore/rustic-io
max_upload_size
id455
size38,687
Nathan Sizemore (nathansizemore)

documentation

README

rustic-io

rustic-io is a simple websocket server library written in Rust. It aims to be an easy to implement, fast, and concurrent websocket server library for event based messaging.

Example Usage

#[deriving(Decodable, Encodable)]
pub struct Foo {
    msg: String
}

fn main() {
    let mut server = rustic_io::new_server("127.0.0.1", "1338");
    server.on("some_event", function_to_execute);
    rustic_io::start(server);
}

fn function_to_execute(data: json::Json, socket: Socket) {
    let json_object = data.as_object().unwrap();

    // Do some stuff with received data...

    // Create some object to send back
    let bar = Foo {
        msg: String::from_str("Hello from Rust!")
    };

    // Send some event back to socket
    socket.send("some_event", json::encode(&bar));

    // Or, broadcast that event to all sockets
    socket.broadcast("some_event", json::encode(&bar));
}

Example Projects

Credits

WebSocket payload implementation from rust-ws

Commit count: 94

cargo fmt