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 |
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 'timeout' | |
socket_path = 'tcp://127.0.0.1:5050' | |
# socket_path = 'ipc://zmq_pub_sub.ipc' | |
ctx = ZMQ::Context.create | |
# Subscriber | |
sub_thread = Thread.new do |
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 'timeout' | |
socket_path = 'tcp://127.0.0.1:5050' | |
# socket_path = 'ipc://zmq_pub_sub.ipc' | |
ctx = ZMQ::Context.create | |
# Subscriber | |
sub_thread = Thread.new do |
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
# Convert an object to JSON, push it over MQTT, | |
# and reconstruct the object. | |
require 'mqtt' | |
require 'json' | |
# ip = '192.168.0.61' | |
ip = '10.0.1.27' | |
send = OpenStruct.new val_1:123, val_2:456 |
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 'timeout' | |
# socket_path = 'tcp://127.0.0.1:5050' | |
# socket_path = 'ipc://zmq_pub_sub.ipc' | |
socket_path = 'epgm://eth0;239.0.0.1:5050' | |
ctx = ZMQ::Context.create | |
# Subscriber |
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 |
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 'zeromqrb' | |
require 'timeout' | |
ctx = ZeroMQ::Context.new | |
# Subscriber | |
sub_thread = Thread.new do | |
sub_sock = ctx.socket ZMQ::SUB | |
sub_sock.setsockopt ZMQ::SUBSCRIBE, '' #Subscribe to everything. |
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
# Works w/ zeromqrb updates. | |
require 'ffi-rzmq' | |
require 'zeromqrb' | |
Thread.abort_on_exception = true | |
class ZeroMQ::Socket | |
def recv_array | |
parts = [] | |
str = '' |
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 'pry' | |
class Read | |
def initialize value = 0 | |
@value = value | |
end | |
def to_s | |
"#{@value}:Read" | |
end |
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
it "send_array attempts an array conversion if the object is not an array" do | |
data = Object.new.tap {|obj| | |
obj.instance_eval { def to_a; [1,2,3,4]; end } | |
} | |
push_sock.send_array data | |
pull_sock.recv_array.should eq data.to_a.map {|i| i.to_s } | |
end |
OlderNewer