python udp

import socket  
  
address = ('127.0.0.1', 5036)  
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
  
while True:  
    msg = raw_input()  
    if not msg:  
        break  
    s.sendto(msg, address)  
  
s.close() 



import socket  
  
address = ('127.0.0.1', 5036)  
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
s.bind(address)  
  
while True:  
    data, addr = s.recvfrom(2048)  
    if not data:  
        print "client has exist"  
        break  
    print "received:", data, "from", addr  
  
s.close() 

 

转载于:https://www.cnblogs.com/testzcy/p/7927859.html

你可能感兴趣的:(python udp)