我是新来扭曲的。我写了一个客户端连接到两个端口8037和8038上的服务器。我知道工厂创建了两个连接对象。现在,当我按下Ctrl-C,它说来自双绞线中的客户端的两个tcp连接
Connection Lost Connection to the other side was lost in a non clean fashion.
Connection Lost Connection to the other side was lost in a non clean fashion.
下面是代码:
from twisted.internet import protocol,reactor
class TestClient(protocol.Protocol):
def __init__(self):
pass
def connectionMade(self):
print "Connected "
self.sayHello()
def connectionLost(self,reason):
self.transport.loseConnection()
def sayHello(self):
self.transport.write("Hello")
def dataReceived(self,data):
print "Received data ",data
class TestClientFactory(protocol.ClientFactory):
def buildProtocol(self,addr):
return TestClient()
def clientConnectionFailed(self,connectory,reason):
print "Connection Failed ",reason.getErrorMessage()
def clientConnectionLost(self,connector,reason):
print "Connection Lost ",reason.getErrorMessage()
reactor.connectTCP("<server_ip>",8037,TestClientFactory())
reactor.connectTCP("<server_ip>",8038,TestClientFactory())
reactor.run()
- 我怎样才能让客户密切双方的TCP连接干净?
- 如何仅为一个连接调用sayHello()方法?
我是新来扭曲,所以一个例子会有所帮助。
感谢
感谢您的回复xiaohen。但是clientConnectionLost中的if条件仍然给我关闭非干净时尚消息的连接。 – Jim
我通过这种方式添加一张新照片;我清理干净。如果你知道解决这个问题的另一种方法,请告诉我。谢谢。 – xiaohen