Skip to content

Instantly share code, notes, and snippets.

@h2suzuki
Created February 16, 2017 10:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h2suzuki/ac36bd67c7179852e9570a8005b53bbe to your computer and use it in GitHub Desktop.
Save h2suzuki/ac36bd67c7179852e9570a8005b53bbe to your computer and use it in GitHub Desktop.
import sys
import zmq
if (len(sys.argv) != 2):
print("Usage: # python3 {} <channel>".format(sys.argv[0]))
sys.exit(1)
ch = sys.argv[1]
# ZeroMQ のバックグラウンド・スレッドのコンテキスト
context = zmq.Context()
# このクライアントは、ポート5556に接続します(バックグラウンドにて)
socket = context.socket(zmq.SUB)
socket.connect("tcp://localhost:5556")
# チャネルの目盛りをあわせる
socket.setsockopt_string(zmq.SUBSCRIBE, ch)
while True:
string = socket.recv_string()
ch, data = string.split()
print("Ch {0} -> {1} received".format(ch, data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment