Last active
August 29, 2015 13:56
-
-
Save amclain/9043178 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' | |
# socket_path = 'tcp://127.0.0.1:5050' | |
socket_path = 'ipc://zmq_hello_world.ipc' | |
ctx = ZMQ::Context.create | |
# Server | |
thread = Thread.new do | |
rep_sock = ctx.socket ZMQ::REP | |
rep_sock.bind socket_path | |
message = '' | |
rep_sock.recv_string message | |
puts "REP Received: #{message}" | |
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 | |
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