server.py 724 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 time
from random import randint

import sn

10
ctx = zmq.Context.instance()
11
# Resources are passed using internal argument parser:
12
sctx = sn.SN(ctx)
13
sock_srv = sctx.get_socket("sock_srv")
Martin Prudek's avatar
Martin Prudek committed
14

15
# Some work:
Martin Prudek's avatar
Martin Prudek committed
16 17 18 19 20 21 22 23 24 25 26 27 28
rand_ID = randint(10,99)
print("server ID (randomly generated)="+str(rand_ID))

while True:
    #  Wait for next request from client
    msg_type, message = sn.parse_msg(sock_srv.recv_multipart())
    message = message.split(":")
    print("(Server " + str(rand_ID) + "): Received request[" + message[1]
            + "] from client " + message[0])
    time.sleep(1)

    sock_srv.send_multipart(sn.encode_msg("sn/test", str(rand_ID) + ":"
            + str(message[1])))