• ZeroMQ


    pip install pyzmq

    zmq_server.py

    import zmq
    
    host = '127.0.0.1'
    port = 6789
    context = zmq.Context()
    server = context.socket(zmq.REP)
    server.bind("tcp://%s:%s" % (host, port))
    
    while True:
        # 等待客户端的下一个请求
        request_bytes = server.recv()
        request_str = request_bytes.decode('utf-8')
        print("That voice in my head says: %s" % request_str)
        reply_str = "Stop saying: %s" % request_str
        reply_bytes = bytes(reply_str, 'utf-8')
        server.send(reply_bytes)

    zmq_client.py

    import zmq
    
    host = '127.0.0.1'
    port = 6789
    context = zmq.Context()
    client = context.socket(zmq.REQ)
    client.connect("tcp://%s:%s" % (host, port))
    
    for num in range(1, 6):
        request_str = "message #%s" % num
        request_bytes = request_str.encode('utf-8')
        client.send(request_bytes)
        reply_bytes = client.recv()
        reply_str = reply_bytes.decode('utf-8')
        print("Sent %s, received %s" % (request_str, reply_str))
    python zmq_server.py &
    python zmq_client.py

  • 相关阅读:
    大数板子
    数位dp
    BM算法
    牛客小白月赛7
    划分树
    可持久化线段树
    素数
    一些数学公式
    线性基
    ConcurrentHashMap 并发HashMap原理分析
  • 原文地址:https://www.cnblogs.com/jzm17173/p/5801531.html
Copyright © 2020-2023  润新知