Last active
June 25, 2022 03:24
-
-
Save silgon/ee609a8df82f0c3d295d8d7c2762b6f8 to your computer and use it in GitHub Desktop.
ZeroMQ interprocess communication server/client REP/REQ
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
| 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() |
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
| 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