Skip to content

Instantly share code, notes, and snippets.

@mlc
Created December 20, 2010 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlc/748886 to your computer and use it in GitHub Desktop.
Save mlc/748886 to your computer and use it in GitHub Desktop.
Demonstrating using XREP/XREQ to talk to a specific client. An abuse of ØMQ?
#!/usr/bin/env ruby
require 'rubygems'
require 'ffi-rzmq'
unless ARGV.size == 1
$stderr.puts "please provide your client identifier on the command-line."
exit 1
end
ctx = ZMQ::Context.new(1)
socket = ctx.socket(ZMQ::XREQ)
socket.setsockopt(ZMQ::IDENTITY, ARGV[0])
socket.connect("tcp://localhost:5678")
while true
socket.recv_string # ignore the delimiter
puts socket.recv_string
end
#!/usr/bin/env ruby
require 'rubygems'
require 'ffi-rzmq'
ctx = ZMQ::Context.new(1)
socket = ctx.socket(ZMQ::XREP)
socket.bind("tcp://*:5678")
while true
$stdout << "enter client: "
client = $stdin.gets.strip
$stdout << "enter message: "
message = $stdin.gets
socket.send_string(client, ZMQ::SNDMORE)
socket.send_string("", ZMQ::SNDMORE)
socket.send_string(message)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment