我想用Python制作一个多进程UDP服务器,从类监听每个进程的一个端口:processListener.py:import multiprocessingimport socketclass processListener(multiprocessing.Process):def __init__(self): multiprocessing.Process.__init__(self) self.data = Nonedef run(self): self.startServer() returndef startServer(self): udpSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) address = ('', self.port) udpSocket.bind(address) while 1: data, client = udpSocket.recvfrom(1024) print self.data, '>>>', data.strip() self.data = data.strip() udpSocket.sendto('ACK', client) return而我的主文件是server.py:from processListener import *# Variable Definitionport = 4000# Sever Initializationif __name__ == '__main__':process = processListener()process.port = portprocess.start()while True: command = raw_input() if command == 'showdata': print 'Last Data is:', process.data当服务器运行时,我从UDP发送数据到localhost:4000shell$ None >>> Test Data但是问题开始于我使用命令 showdatashell$None >>> Test DatashowdataLast Data is: None
添加回答
举报
0/150
提交
取消