Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZMQ poller implementation not working with TCP, but working with IPC #35

Open
shiraazsd opened this issue May 31, 2016 · 0 comments
Open

Comments

@shiraazsd
Copy link

I have a scenario of REQ/ REP where the replier keeps polling for any requests coming from the requester using the standard poller apis.
we have a ruby implementation of the above scenario.
The issue we are facing is that the above scenario works only with the ipc protocol and not with the tcp protocol(in the bind and connect urls of replier and requester respectively).
However if we go by the standard requester / replier with the send/receive function then the whole process works well with the tcp and ipc protocol both.
The issue happens on changing the the replier code to the poller implementation and the requester/replier are not able to communicate with each other.

We also tried out the corresponding C++ implementation and it seems to work fine for both tcp/ipc protocols and both standard/poller implementations
I want to know if there is any important part missing in the code or some OS setting that needs to be changed to get the ruby code working with the poller implementation?

RUBY implementation

REQUESTER

require 'rubygems'
require 'ffi-rzmq'

context = ZMQ::Context.new

puts "Connecting to the Server..."
requester = context.socket(ZMQ::REQ)
requester.connect("tcp://localhost:5555")
puts "Calling server"
requester.send_string 'Shiraaz'
puts 'After send'
reply = ''
requester.recv_string(reply)
puts 'After receieve'
puts reply

REPLIER with standard receive/send implementation

require 'rubygems'
require 'ffi-rzmq'

context = ZMQ::Context.new

puts "Connecting to the Server..."
requester = context.socket(ZMQ::REQ)
requester.connect("tcp://localhost:5555")
puts "Calling server"
requester.send_string 'Shiraaz'
puts 'After send'
reply = ''
requester.recv_string(reply)
puts 'After receieve'
puts reply

REPLIER with poller implementation

require 'rubygems'
require 'ffi-rzmq'

puts "Starting Server..."

context = ZMQ::Context.new
socket  = context.socket(ZMQ::REP)
socket.bind("tcp://localhost:5555")  //This does not works...But changing  it to socket.bind("ipc:///tmp/feed") and making the same change in the requester connect url makes it work
poller = ZMQ::Poller.new
poller.register(socket, ZMQ::POLLIN)
loop do
  puts 'Before poll'
  poller.poll(1000)
  request = ''
  puts 'After poll'
  poller.readables.each do |sock|
     puts 'here'
     if sock === socket
           sock.recv_string(request)
           puts "Received request. Data: #{request.inspect}"
           sock.send_string('Reply from the server')
     end
  end
end

Version info:-

ruby : 1.8.7
rubygems : 1.8.25
ffi : 1.0.10
ffi-rzmq : 0.9.7
OS : rhel 7.2
g++ : 4.8.5
zmq : 3.2.5-1.el7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant