Skip to content

Instantly share code, notes, and snippets.

@thehydroimpulse
Created August 25, 2014 16:53
Show Gist options
  • Save thehydroimpulse/4455fad2cf09c7f5eb2b to your computer and use it in GitHub Desktop.
Save thehydroimpulse/4455fad2cf09c7f5eb2b to your computer and use it in GitHub Desktop.
extern crate gossip;
use gossip::{Server};
fn main() {
// Node A
spawn(proc() {
// Create a new node.
let mut server = Server::new();
// Bind the server to the local address and port.
server.listen("localhost", 7888);
// Get a new iterator for incoming messages.
for message in server.msg_iter() {
println!("Received a new message. Node: {} Message: {}", message.node.id, message.bytes);
}
});
// Node B
let mut server = Server::new();
// Bind the server to the local address and port. This will spawn a new
// task for the server.
server.listen("localhost", 9888);
// Join Node A's cluster.
match server.join("localhost", 7888) {
Ok(_) => {},
Err(err) => fail!("Failed to join the cluster. Peer: {}", err.peer)
}
// Send a broadcast to the correct nodes (right now it's only one).
server.broadcast("Foobar".to_string());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment