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()); }