server udp | udp client - cycle message

# ### udp cycle message server 
Import socket 
SK = socket.socket (of the type = socket.SOCK_DGRAM) 
# bind address (registered the hosts on the network, so that others find you) 
sk.bind (( "127.0.0.1 ", 9000)) 

the while True: 
	msg, cli_addr = sk.recvfrom (1024) 
	Print (cli_addr) 
	Print (msg.decode (" UTF-8 ")) 
	
	the Message = the INPUT (" I have to say >> ") 
	# cli_addr ( '127.0.0.1', 58745) 
	sk.sendto (message.encode ( "UTF-. 8"), cli_addr) 


# udp close connection 
sk.close ()
# ### udp cycle message client 
Import socket 
SK = socket.socket (of the type = socket.SOCK_DGRAM) 

the while True: 
	# sending data 
	message = input ( "To send a message >>") 
	sk.sendto (message.encode ( "UTF-. 8"), ( "127.0.0.1", 9000)) 

	# accept data 
	MSG, addr = sk.recvfrom (1024) 
	Print (msg.decode ( "UTF-. 8")) 
# udp close connection 
sk. close ()

  

Guess you like

Origin www.cnblogs.com/huangjiangyong/p/10960930.html