Created
December 20, 2010 19:45
-
-
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?
This file contains 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
#!/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 |
This file contains 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
#!/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