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() 

 

posted on 2017-11-30 10:43  我和你并没有不同  阅读(221)  评论(0编辑  收藏  举报