Last active
August 29, 2015 13:56
-
-
Save amclain/9127891 to your computer and use it in GitHub Desktop.
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 'ffi-rzmq' | |
require 'zeromqrb' | |
# socket_path = 'tcp://127.0.0.1:5050' | |
socket_path = 'ipc://zmq_hello_world.ipc' | |
# ctx = ZMQ::Context.create | |
ctx = ZeroMQ::Context.new | |
# Server | |
thread = Thread.new do | |
rep_sock = ctx.socket ZMQ::ROUTER | |
rep_sock.bind socket_path | |
client_id = '' | |
message = '' | |
rep_sock.recv_string client_id | |
p client_id | |
rep_sock.recv_string message | |
p message | |
rep_sock.recv_string message | |
p message | |
puts "REP Received: #{message}" | |
rep_sock.send_string client_id, ZMQ::SNDMORE | |
rep_sock.send_string '', ZMQ::SNDMORE | |
rep_sock.send_string 'Goodbye' | |
rep_sock.close | |
end | |
# Client | |
req_sock = ctx.socket ZMQ::REQ | |
req_sock.connect socket_path | |
req_sock.send_string 'Hello' | |
reply = '' | |
req_sock.recv_string reply | |
p reply | |
puts "REQ Received: #{reply}" | |
req_sock.close | |
# Cleanup | |
thread.join | |
ctx.terminate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment