~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to Code_python/DocServer/Templates/hwserver.py

  • Committer: Dave Kuhlman
  • Date: 2015-10-03 18:25:17 UTC
  • mfrom: (35.1.5 Materials)
  • Revision ID: dkuhlman@davekuhlman.org-20151003182517-b2m7eltjdapw46zh
Review for Cisco.  Merged checkpoint 10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#   Hello World server in Python
 
3
#   Binds REP socket to tcp://*:5555
 
4
#   Expects b"Hello" from client, replies with b"World"
 
5
#
 
6
 
 
7
import time
 
8
import zmq
 
9
 
 
10
context = zmq.Context()
 
11
socket = context.socket(zmq.REP)
 
12
socket.bind("tcp://*:5555")
 
13
 
 
14
while True:
 
15
    #  Wait for next request from client
 
16
    message = socket.recv()
 
17
    print("Received request: %s" % message)
 
18
 
 
19
    #  Do some 'work'
 
20
    time.sleep(1)
 
21
 
 
22
    #  Send reply back to client
 
23
    socket.send(b"World")