I have the following code and I want to detect in which port client is connected to factory. How can I achieve that?
from twisted.internet import reactor
conn = txredisapi.lazyRedisConnectionPool(reconnect = True)
factory = STSFactory(conn)
factory.clients = []
print "Server started"
reactor.listenTCP(11000,factory)
reactor.listenTCP(11001,factory)
reactor.listenTCP(11002,factory)
reactor.run()
The two addresses of a TCP connection, the client address and the server address, can be retrieved using the transport’s
getHostandgetPeermethods. The “host” address is the address of the local side of the connection. The “peer” address is the address of the other side of the connection. On a server, the host address is also the address of the port which accepted the connection.You can read about transport methods in the Twisted API documentation.
For example: