client.py 847 Bytes
Newer Older
Martin Prudek's avatar
Martin Prudek committed
1 2
#!/usr/bin/env python3

3
import zmq
Martin Prudek's avatar
Martin Prudek committed
4 5 6 7 8 9
import sys
import sn
import time

from random import randint

10 11

ctx = zmq.Context.instance()
12 13 14 15
sctx = sn.Resources(ctx)
# Resources are passed using internal argument parser:
# Socket "sock_cli" is enforced to be "REQ" type:
sock_cli = sctx.get_socket(("sock_cli","REQ"))
Martin Prudek's avatar
Martin Prudek committed
16

17 18

# Some work:
Martin Prudek's avatar
Martin Prudek committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
rand_ID = randint(10,99)
print("client ID (randomly generated)="+str(rand_ID))

for request in range(1, 4):
    message = randint(100, 999)
    print("(Client " + str(rand_ID) + "): Sending request["+str(message)+"]")

    sock_cli.send_multipart(sn.encode_msg("sn/test", str(rand_ID) + ":" + str(message)))
    msg_type, message = sn.parse_msg(sock_cli.recv_multipart())
    message = message.split(":")

    print("(Client " + str(rand_ID) + "): Received reply[" + message[1] + "] from server  " + message[0])


time.sleep(1)