python network programming dry

A. TCP-based socket

1. Basic

end server

Import socket 
SK = socket.socket () 
sk.bind (( ' 127.0.0.1 ' , 9000)) # the address bound to the socket 
sk.listen () # monitor link 

conn, addr = sk.accept () # waiting to answer customer links 

conn.send () # send a message to the client 
conn.recv (1024) # accept client information 

conn.Close () # close the connection 
sk.close () # close the server socket

client end

Import Socket 
SK = socket.socket () # Create client side socket 
sk.connect (( ' 127.0.0.1 ' , 9000)) # links server side 

sk.recv ( 1024) # receiving server sent messages 
sk.send ( ) # to the server sends a message 

sk.close () # close the client side socket

 

Guess you like

Origin www.cnblogs.com/shi-py-rengongzhineng/p/11666247.html