[Network Programming] Network Programming examples

Server:

Socket Import 

our sock = socket.socket ()
 # Binding ip and port 
sock.bind (( ' 192.168.1.6 ' , 8000 ))
 # The maximum number of lines for five 
sock.listen (. 5 )
 # wait for a client to connect to, if not people foolishly wait. 
# Conn object client and server connection, after the server to send and receive data through the object. 
# Addr is the address of the client information 
Conn, addr = sock.accept () 

Response = conn.recv (1024) # of bytes type (up to once obtain 1024 bytes) 
Print (Response) 

# by an object reply message 
conn.send (b ' STOP ' ) 
conn.Close ()

 Client:

Import Socket 

SK = socket.socket () 
sk.connect (( ' 192.168.1.6 ' , 8000 )) 

# send information to the server 
sk.send (B ' Hello ' ) 

# acquires information returned from the server 
response = sk.recv ( 1024 )
 Print (response.decode ( ' UTF-. 8 ' ))

 

Guess you like

Origin www.cnblogs.com/htybky/p/11488855.html