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()
新闻热点
疑难解答