我正在尝试使用 Twisted 框架编写服务器,并希望多次接收数据
class Echo(Protocol):
def connectionMade(self):
print " got connection from : " + str(self.transport.getPeer())
def dataReceived(self, data):
'''
get the client ip
'''
if(len(data)>40):
'''
initial setup message from the client
'''
client_details = str(self.transport.getPeer())#stores the client IP as a string
i = client_details.find('\'')#process the string to find the ip
client_details = client_details[i+1:]
j = client_details.find('\'')
client_ip = client_details[:j]
'''
Extract the port information from the obtained text
'''
data = data.split('@')
port1 = data[0]
port2 = data[1]
port3 = data[2]
if int(data) == 1:
method1(client_ip,port1)
if int(data) == 2:
method2(client_ip,port2)
我的问题:只有当它从客户端接收到包含适当整数数据的消息时,才会调用 method1 和 method2。有没有一种方法可以让我等待客户端接收 dataReceived() 方法中的数据,还是应该在 dataReceived() 方法本身中按顺序进行?