码迷,mamicode.com
首页 > 编程语言 > 详细

python socket编程 UDP

时间:2014-12-10 18:04:37      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:python   socket   udp   

python socket编程 UDP

by 伍雪颖

server.py
import socket

BUF_SIZE = 1024
server_addr = ('127.0.0.1',8888)
server = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
server.bind(server_addr)
while True:
     print "waiting for data"
     data,client_addr = server.recvfrom(BUF_SIZE)
     print 'Connected by ',client_addr,' Receive data : ',data
     server.sendto(data,client_addr)
server.close()

client.py
import socket
import struct

BUF_SIZE = 1024
server_addr = ('127.0.0.1',8888)
client = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

while True:
     data = raw_input("Please input some string > ")
     client.sendto(data,server_addr)
     data,addr = client.recvfrom(BUF_SIZE)
     print "Data : ",data
client.close()


python socket编程 UDP

标签:python   socket   udp   

原文地址:http://blog.csdn.net/rainlesvio/article/details/41849111

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!