首页 > 代码库 > python udp编程实例
python udp编程实例
与python tcp编程对比见 http://blog.csdn.net/aspnet_lyc/article/details/39854569
c++ udp/tcp 编程见 http://blog.csdn.net/aspnet_lyc/article/details/38946915
http://blog.csdn.net/aspnet_lyc/article/details/34444111
server
import socketPORT = 9999BIND_ADDR = ''MAXLINE = 1024buf = []listenfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)listenfd.bind((BIND_ADDR, PORT))while True: buf, client_addr = listenfd.recvfrom(MAXLINE) print 'recieve data from %s: %s' % (client_addr, buf) buf = 'Hello, this is server' listenfd.sendto(buf, client_addr)
client
import socketPORT = 9999SADDR = '127.0.0.1'MAXLINE = 1024buf = 'Hello, this is client'sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)sockfd.sendto(buf, (SADDR, PORT))buf,server_addr = sockfd.recvfrom(MAXLINE)print 'recieve data from server: %s' % buf
python udp编程实例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。