~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to Code_python/DocServer/Templates/hwclient.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 client in Python
 
3
#   Connects REQ socket to tcp://localhost:5555
 
4
#   Sends "Hello" to server, expects "World" back
 
5
#
 
6
 
 
7
import zmq
 
8
 
 
9
context = zmq.Context()
 
10
 
 
11
#  Socket to talk to server
 
12
print("Connecting to hello world server...")
 
13
socket = context.socket(zmq.REQ)
 
14
socket.connect("tcp://localhost:5555")
 
15
 
 
16
#  Do 10 requests, waiting each time for a response
 
17
for request in range(10):
 
18
    print("Sending request %s ..." % request)
 
19
    socket.send(b"Hello")
 
20
 
 
21
    #  Get the reply.
 
22
    message = socket.recv()
 
23
    print("Received reply %s [ %s ]" % (request, message))