Created
January 29, 2013 15:19
-
-
Save robotmay/4665019 to your computer and use it in GitHub Desktop.
Playing around with Rust and ZMQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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