2011-12-19 133 views
1

我有一个非常简单的客户端程序:扭曲客户端连接丢失

class EchoClient(Int32StringReceiver): 

    def connectionMade(self): 
     print 'connection made.' 
     str = "<request><commands><dbtest /></commands></request>" 
     self.sendString(str) 
     print 'message sent' 

    def stringReceived(self, line): 
     print "receive:", line 
     self.transport.loseConnection() 

class EchoClientFactory(ClientFactory): 

    def buildProtocol(self, addr): 
     return EchoClient() 

    def clientConnectionFailed(self, connector, reason): 
     print 'connection failed:', reason.getErrorMessage() 
     reactor.stop() 

    def clientConnectionLost(self, connector, reason): 
     print 'connection lost:', reason.getErrorMessage() 
     reactor.stop() 

def main(): 
    factory = EchoClientFactory() 
    reactor.connectTCP('localhost', 3604, factory) 
    reactor.run() 

我连接到了Apache CXF实现的Java服务(以及一些专有公司代码)。

它连接好,发送消息,服务接收它并产生响应。

不幸的是,这个客户端不会等待服务器产生它的消息,而是在消息发送后立即断开连接。所以输出我从客户得到的是:

connection made. 
message sent 
connection lost: Connection was closed cleanly. 

当然,Java服务将引发异常抱怨连接处于已关闭。

我在这里错过了什么?

编辑:添加此行显示接收到消息,因为它正确打印它:

def dataReceived(self, data): 
    print(data) 
    self.transport.loseConnection() 

所以,真正的问题是,stringReceived()函数没有被调用。也许我有这个功能的错误签名?

回答

0

我到这里的东西:

def lengthLimitExceeded(self, length): 
    print('length limit exceeded: {}'.format(length)) 

打印:

length limit exceeded: 2147483793 
length limit exceeded: 2147483793 

是0x80000091,这样看来,我们的propietary API正在实施NString协议在陌生的路上(也许用途MSB的其他东西)。

+1

这不是一个真正的答案。您可能想要将此信息添加到问题中。 – 2011-12-19 19:17:08