Skip to content

Instantly share code, notes, and snippets.

@rizo
Last active January 3, 2016 06:28
Show Gist options
  • Select an option

  • Save rizo/8422417 to your computer and use it in GitHub Desktop.

Select an option

Save rizo/8422417 to your computer and use it in GitHub Desktop.
Simple experiment with nanomsg.
# -- 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