Skip to content

Instantly share code, notes, and snippets.

View amclain's full-sized avatar

Alex McLain amclain

View GitHub Profile
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
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
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
# 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
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
# 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
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.
# Works w/ zeromqrb updates.
require 'ffi-rzmq'
require 'zeromqrb'
Thread.abort_on_exception = true
class ZeroMQ::Socket
def recv_array
parts = []
str = ''
require 'pry'
class Read
def initialize value = 0
@value = value
end
def to_s
"#{@value}:Read"
end
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