Skip to content

Instantly share code, notes, and snippets.

@grantr grantr/gist:4526886
Created Jan 13, 2013

Embed
What would you like to do?
zmq router sockets double connect
>> require 'ffi-rzmq'
=> true
>> ctx = ZMQ::Context.new
=> #<ZMQ::Context:0x00000001ae9d30 @io_threads=1, @max_sockets=1024, @context=#<FFI::Pointer address=0x00000001c46690>>
>> r1 = ctx.socket(ZMQ::ROUTER)
=> #<ZMQ::Socket:0x00000001b05170 @receiver_klass=ZMQ::Message, @socket=#<FFI::Pointer address=0x00000001e44e00>, @name="ROUTER", @int_cache=nil, @longlong_cache=nil, @more_parts_array=[], @option_lookup=[nil, nil, nil, nil, 1, 2, 2, 2, 0, 0, nil, 0, 0, 1, 0, 0, 0, 0, 0, 0, nil, 0, 1, 0, 0, nil, nil, 0, 0, nil, nil, 0, nil, 0, 0, 0, 0, 0, 0]>
>> r2 = ctx.socket(ZMQ::ROUTER)
=> #<ZMQ::Socket:0x00000001b074e8 @receiver_klass=ZMQ::Message, @socket=#<FFI::Pointer address=0x00000001cbbe20>, @name="ROUTER", @int_cache=nil, @longlong_cache=nil, @more_parts_array=[], @option_lookup=[nil, nil, nil, nil, 1, 2, 2, 2, 0, 0, nil, 0, 0, 1, 0, 0, 0, 0, 0, 0, nil, 0, 1, 0, 0, nil, nil, 0, 0, nil, nil, 0, nil, 0, 0, 0, 0, 0, 0]>
>> r1.setsockopt(ZMQ::IDENTITY, "r1")
=> 0
>> r2.setsockopt(ZMQ::IDENTITY, "r2")
=> 0
>> r1.bind("tcp://127.0.0.1:48000")
=> 0
>> r2.bind("tcp://127.0.0.1:48001")
=> 0
>> r1.connect("tcp://127.0.0.1:48001")
=> 0
>> r2.connect("tcp://127.0.0.1:48000")
=> 0
>> r1.send_strings(["r2", "hello1"])
=> 6
>> r1.send_strings(["r2", "hello2"])
=> 6
>> a = []; r2.recv_strings(a); puts a.inspect
["r1", "hello1"]
=> nil
>> a = []; r2.recv_strings(a); puts a.inspect
["r1", "hello2"]
=> nil
>> r2.send_strings(["r1", "hello3"])
=> 6
>> a = []; r1.recv_strings(a); puts a.inspect
["r2", "hello3"]
=> nil
>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.