Skip to content

Instantly share code, notes, and snippets.

@rebekah
Created March 6, 2014 03:09
Show Gist options
  • Save rebekah/9381525 to your computer and use it in GitHub Desktop.
Save rebekah/9381525 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'ffi-rzmq'
require 'pry'
class Client
def initialize()
@connections = {queue_req: {type: ZMQ::REQ, location: "tcp://localhost:5555"}, queue_rep: {type: ZMQ::REP, location: "tcp://*:5555"}}
end
attr_accessor :connections
def create_requester(type, location, socket_id = nil)
context = ZMQ::Context.new(1)
puts "Connecting to hello world server..."
requester = context.socket(type)
if socket_id; requester.setsockopt(ZMQ::IDENTITY, socket_id); end
requester.connect(location)
requester
end
end
class Server
def initialize()
@connections = {queue_req: {type: ZMQ::REQ, location: "tcp://localhost:5555"}, queue_rep: {type: ZMQ::REP, location: "tcp://*:5555"}}
@running = true
end
attr_accessor :connection, :running
def stop
@running = false
end
def create_receiver(type,location,context = nil)
context = ZMQ::Context.new(1) unless context
puts "Starting Hello World server..."
# socket to listen for clients
socket = context.socket(type)
socket.bind(location)
[socket, context]
end
def do_action(context, id, message)
handler = context.socket(ZMQ::DEALER)
handler.connect('inproc://backendssss')
sleep(3)
puts "doing threaded procedure with #{message}"
handler.send_string("#{message}")
puts "handler finished"
handler.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment