looks like its similar to mqtt but faster and more flexiable written in c/c++, and supports bindings in python (most docs are in c++) does not require a server
- frames are (message parts) blocks of data with specific length. has garente of being recieved at the other end
- to send large files spliting up into parts.
- sent with out a trialing NULL 'asdfasdf\0' is 'asdfa\0'
- have specified length
-
normal: client and server make connection
-
zmq: each connection to socket creates its own que, allowing for 1-many, many-1, many-many
- ROUTER: is the acception, only create que if peer has acknowleged the connection, AKA confirm before setup
-
Ha funny: form a karmic circle of socket life ZeroMQ | Socket API
Python Client example Hello World client in Python - ØMQ - The Guide
import zmq
context = zmq.Context()
# Socket to talk to server
print("Connecting to hello world server…")
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5555")
# Do 10 requests, waiting each time for a response
for request in range(10):
print("Sending request %s …" % request)
socket.send(b"Hello")
# Get the reply.
message = socket.recv()
print("Received reply %s [ %s ]" % (request, message))
Python Server example Hello World server in Python - ØMQ - The Guide
t time
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")
while True:
# Wait for next request from client
message = socket.recv()
print("Received request: %s" % message)
# Do some 'work'
time.sleep(1)
# Send reply back to client
socket.send(b"World")
- Because zmq doesnt require trailing null in string being sent
- can cause weird results. rule of thumb copy string a terminate with \0 every time
- weather server
zmq.PUB
import zmq
from random import randrange
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5556")
while True:
zipcode = randrange(1, 100000)
temperature = randrange(-80, 135)
relhumidity = randrange(10, 60)
socket.send_string("%i %i %i" % (zipcode, temperature, relhumidity))
- weather client
zmq.SUB
import sys
import zmq
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Collecting updates from weather server…")
socket.connect("tcp://localhost:5556")
# Subscribe to zipcode, default is NYC, 10001
zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001"
# Python 2 - ascii bytes to unicode str
if isinstance(zip_filter, bytes):
zip_filter = zip_filter.decode('ascii')
socket.setsockopt_string(zmq.SUBSCRIBE, zip_filter)
# Process 5 updates
total_temp = 0
for update_nbr in range(5):
string = socket.recv_string()
zipcode, temperature, relhumidity = string.split()
total_temp += int(temperature)
print("Average temperature for zipcode '%s' was %dF" % (
zip_filter, total_temp / (update_nbr+1))
)
- Go through this guide ØMQ - The Guide - ØMQ - The Guide
- Python install zeromq.org/download.md at master · zeromq/zeromq.org
- install ZeroMQ | Download
- SOCKETS https://zeromq.org/socket-api/
- zmq vs mqtt
- how fast is zeromq
- what is its common usecases
- if it has no configuration then what does it do?
- does it allow for functions to be called on server with request?
- what is RPC?
what is #f