A client that reads information from a server and display that information. : Client « Network « Python Tutorial






import socket

HOST = "127.0.0.1"
PORT = 5000

mySocket = socket.socket( socket.AF_INET, socket.SOCK_STREAM )

try:
   mySocket.connect( ( HOST, PORT ) )
except socket.error:
   print "Call to connect failed"

serverMessage = mySocket.recv( 1024 )

while serverMessage != "TERMINATE":
   if not serverMessage:
      break

   print serverMessage
   clientMessage = "1234"
   mySocket.send( clientMessage )
   serverMessage = mySocket.recv( 1024 )

mySocket.close()








21.1.Client
21.1.1.A Minimal Client
21.1.2.Opening a Client-Side Socket for Sending Data
21.1.3.TCP Timestamp Client
21.1.4.A client that reads information from a server and display that information.