我正在尝试开发一种混合协议,它可以根据请求返回原始响应或基于Line的响应。我的代码看起来像这样
class Receiver(LineReceiver):
def lineReceived(self, line):
(command, args) = self._parse_command(line)
result = self.exec_command(command, args) #Secret sauce returns list or blob.
if isinstance(result, basestring): # won't work in 3.0 ; least of my worries.
self.sendLine(str(len(result))) # Sends no. of bytes as a line.
self.transport.write(result) #followed by bytes. This is not received by the client.
self.transport.loseConnection()
else:
no_lines = len(result)
self.sendLine(str(no_lines))
for r in result:
self.sendLine(str(r))在上面的代码中transport.write(...)不向客户端发送任何数据。我怎么才能解决这个问题。
发布于 2011-11-29 01:46:12
transport.write调用将数据发送到客户端。如果客户端写得不好,它可能会丢失它,因为连接在数据发送后立即关闭。还有许多其他可能导致客户端失败的原因,但由于客户端代码不是问题的一部分,因此无法知道实际发生了什么。
https://stackoverflow.com/questions/8298177
复制相似问题