I'm using Twisted to write a proxy server and I'm having issues with checking if a connection to the server was closed.
As it is now, I have
client <-> proxy <-> server
Testing with telnet, the proxy successfully passes messages from the client to the server, and passes the servers response back to the client. However, my issue is if the client issues a command to close the connection between the proxy and the server, the connection between the client and the proxy still remains.
Here is some of my code
client_factory = protocol.ClientFactory()
client_factory.protocol = ClientTelnetProtocol
client_factory.proxy = self
try:
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('localhost', 1234))
clientsocket.close()
reactor.connectTCP('localhost', 1234, client_factory)
except Exception as err:
print(err)
self.transport.loseConnection()
In the line
reactor.connectTCP('localhost', 1234, client_factory)
I want to be able to monitor the state of the connection and see if the server closes it, possibly on dataReceived() or if possible, have set up an interrupt when the server closes the connection to the proxy, and have the proxy immediately close the connection to the client.