Skip to content

Instantly share code, notes, and snippets.

@fumiyas
Created October 5, 2012 00:47
Show Gist options
  • Save fumiyas/3837402 to your computer and use it in GitHub Desktop.
Save fumiyas/3837402 to your computer and use it in GitHub Desktop.
ZMQ recv demo
#!/usr/bin/env ruby
require "rubygems"
require "zmq"
require 'json'
context = ZMQ::Context.new(1)
inbound = context.socket(ZMQ::UPSTREAM)
inbound.bind("tcp://127.0.0.1:9000")
Signal.trap('INT') {
puts "SIGINT"
}
loop do
puts "sleeping"
begin
text = inbound.recv
rescue ZMQ::Error
redo
end
obj = JSON.parse(text)
p obj
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment