Wu Yuxiong - born naturally PYTHON3 development of learning: Network Programming

# Import socket, sys module 
Import socket
 Import SYS 

# Create a socket object 
serversocket = socket.socket ( 
            socket.AF_INET, socket.SOCK_STREAM) 

# get the local hostname 
Host = socket.gethostname () 

Port = 9999 # Bind port number serversocket. the bind ((Host, Port)) # set the maximum number of connections, the queue exceeds 
serversocket.listen (. 5 ) the while True:
     # clients connect 
    ClientSocket, addr = ServerSocket.accept ()       Print ( " connection address:% S " % str (addr))








    
    
    msg = ' Welcome to the rookie tutorial! ' + " \ R & lt \ n- " 
    clientsocket.send (msg.encode ( ' UTF-. 8 ' )) 
    clientsocket.close ()
# Import socket, sys module 
Import socket
 Import SYS 

# Create a socket object 
S = socket.socket (socket.AF_INET, socket.SOCK_STREAM) 

# obtains the local host name 
Host = socket.gethostname () 

# set the port number 
Port = 9999 # connection service , specified host and port s.connect ((host, port)) # receiving less than 1024 bytes of data 
MSG = s.recv (1024 ) 
S.CLOSE () Print (msg.decode ( ' UTF-. 8 ' ))







 

Guess you like

Origin www.cnblogs.com/tszr/p/10965696.html