How to get the client IP address after got connection lost in twisted

前端 未结 2 1697
梦毁少年i
梦毁少年i 2021-01-03 08:21

I know we can get the client (host) IP after connection has been established because at that time we will have transport attribute:

self.transport.getPeer()
         


        
2条回答
  •  滥情空心
    2021-01-03 08:59

    Its a little late for that. I suggest you save this information when you have it. For example:

    class YourProtocol(protocol.Protocol):
    
        def connectionMade(self):
            self._peer = self.transport.getPeer()
    
        def connectionLost(self):
            print 'Lost connection from', self._peer
    

提交回复
热议问题