Skip to content

Instantly share code, notes, and snippets.

@silgon
Last active June 25, 2022 03:24
Show Gist options
  • Select an option

  • Save silgon/ee609a8df82f0c3d295d8d7c2762b6f8 to your computer and use it in GitHub Desktop.

Select an option

Save silgon/ee609a8df82f0c3d295d8d7c2762b6f8 to your computer and use it in GitHub Desktop.
ZeroMQ interprocess communication server/client REP/REQ
import zmq
import sys
context = zmq.Context()
print "Connecting to server..."
socket = context.socket(zmq.REQ)
socket.connect ("ipc://test_hello")
# Do 10 requests, waiting each time for a response
for request in range (1,10):
print "Sending request ", request,"..."
socket.send ("Hello")
# Get the reply.
message = socket.recv()
print "Received reply ", request, "[", message, "]"
socket.close()
context.term()
import zmq
import time
import sys
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("ipc://test_hello")
while True:
# Wait for next request from client
message = socket.recv()
print "Received request: ", message
time.sleep (1)
socket.send("World from ipc")
socket.close()
context.term()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment