首页 > 学院 > 开发设计 > 正文

udp socket

2019-11-06 07:45:30
字体:
来源:转载
供稿:网友

import timefrom socket import *HOST = ""PORT = 9999BUFSIZE = 1024ADDR = (HOST, PORT)udpSerScok = socket(AF_INET, SOCK_DGRAM)udpSerScok.bind(ADDR)while True:    PRint 'waiting for message...'    data, addr = udpSerScok.recvfrom(BUFSIZE)    udpSerScok.sendto('[%s] %s'%(time.ctime(), data), addr)    print 'received from and returned to :' , addr       udpSerScok.close()

from socket import *HOST = 'localhost'PORT = 9999BUFSIZE = 1024ADDR = (HOST, PORT)udpCliSock = socket(AF_INET, SOCK_DGRAM)while True:    data = raw_input('>')    if not data:        break        udpCliSock.sendto(data, ADDR)    data = udpCliSock.recvfrom(BUFSIZE)    if not data:        break    print data    tcpCliSock.close()


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表