Created
February 17, 2017 07:12
-
-
Save h2suzuki/cfdcb9cdbb9e365f748dd3df0ec882d5 to your computer and use it in GitHub Desktop.
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 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