python in the server TCP communication connection

import socket # import socket module 
host = "127.0.0.1" # Host IP
Port = port number 8080 #
web = socket.socket () # Create a socket object
web.bind ((host, port)) # bind port number
web. listen (5) # set the connection largest number of
print ( "server waits for a client to connect ......")
# Enable infinite loop
the while True:
conn, addr = web.accept () # client connection
data = conn. recv (1024) # data acquisition client requests
data print (data) # printing received
conn.sendall (b'HTTP / 1.1 200 OK \ r \ n \ r \ nHello World ') # sending data to the client "HTTP / 1.1 200 OK" return request Baidu browser running
input # 127.0.0.1: 8080, in response to information Hello World (browser)
conn.Close () # close the connection

Guess you like

Origin www.cnblogs.com/wangjingye/p/12153224.html