Skip to content

Instantly share code, notes, and snippets.

@robotmay
Created January 29, 2013 15:19
Show Gist options
  • Save robotmay/4665019 to your computer and use it in GitHub Desktop.
Save robotmay/4665019 to your computer and use it in GitHub Desktop.
Playing around with Rust and ZMQ
require "celluloid/zmq"
Celluloid::ZMQ.init
class Client
include Celluloid::ZMQ
def initialize(address)
@socket = PushSocket.new
begin
@socket.bind(address)
rescue IOError
@socket.close
raise
end
end
def write(message)
@socket.send(message)
end
end
extern mod zmq;
fn server(ctx: zmq::Context) {
let socket = result::unwrap(ctx.socket(zmq::PULL));
socket.connect("tcp://127.0.0.1:9000").get();
loop {
let msg = result::unwrap(socket.recv_str(0));
io::println(fmt!("Received: %s", msg));
}
}
fn main() {
let ctx = result::unwrap(zmq::init(1));
server(ctx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment