Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import sys
import zmq
import time
if (len(sys.argv) != 2):
print("Usage: # python3 {} {{alphabet|number}}".format(sys.argv[0]))
sys.exit(1)
mode = sys.argv[1]
# ZeroMQ のバックグラウンド・スレッドのコンテキスト
context = zmq.Context()
# このクライアントは、ポート5556に接続します(バックグラウンドにて)
socket = context.socket(zmq.PUB)
socket.connect("tcp://localhost:5556")
i = 0
while True:
i += 1
if mode == "alphabet":
lower = chr(ord('a') + (i - 1) % 26)
socket.send_string("1 " + lower)
print("Ch 1 <- {} sent".format(lower))
upper = chr(ord('A') + (i - 1) % 26)
socket.send_string("2 " + upper)
print("Ch 2 <- {} sent".format(upper))
else:
for ch in range(1,3):
number = ch * i
socket.send_string("{0} {1}".format(ch, number))
print("Ch {0} <- {1} sent".format(ch, number))
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment