Last active
January 3, 2016 06:28
-
-
Save rizo/8422417 to your computer and use it in GitHub Desktop.
Simple experiment with nanomsg.
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
| # -- server.py -- | |
| from datetime import datetime | |
| import nanomsg as nn | |
| import time | |
| ADDRESS = 'tcp://*:5556' | |
| socket = nn.Socket(nn.REP) | |
| socket.bind(ADDRESS) | |
| print("Server is running...") | |
| while True: | |
| reqmsg = socket.recv() | |
| print(".") | |
| if (reqmsg == b"date"): | |
| repmsg = str(datetime.now()) | |
| bytes_sent = socket.send(repmsg) | |
| # -- client.py -- | |
| import nanomsg as nn | |
| ADDRESS = 'tcp://127.0.0.1:5556' | |
| socket = nn.Socket(nn.REQ) | |
| socket.connect(ADDRESS) | |
| for i in range(10): | |
| reqmsg = "date" | |
| socket.send(reqmsg) | |
| repmsg = socket.recv() | |
| print(repmsg) | |
| socket.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment