Socket Programming Example (cont)
Client Program
- Connect to time server and get current time
# Time client program
from socket import *
s = socket(AF_INET,SOCK_STREAM) # Create TCP socket
s.connect(("makemepoor.com",8888)) # Connect to server
tm = s.recv(1024) # Receive up to 1024 bytes
s.close() # Close connection
print "The time is", tm
Key Points
- Once connection is established, server/client communicate using send() and recv().
- Aside from connection process, it's relatively straightforward.
- Of course, the devil is in the details.
- And are there ever a LOT of details.
|