from twisted.internet.protocol import Protocol, ClientFactory
from twisted.internet import reactor

from datetime import datetime

class RunOnAgent(Protocol):

	def dataReceived(self, data):
		print "Received ", data

	def connectionMade(self):
		self.transport.write("RESPOND")

class AgentRunFactory(ClientFactory):

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

	def clientConnectionLost(self, connector, reason):
		if "cleanly" not in str(reason):
			print "Log conenction ", reason,

	def clientConnectionFailed(self, connector, reason):
		print "Failed to connect"	

	def startedConnecting(self, connector):
		pass


if __name__ == "__main__":
	for i in range(10):
		reactor.connectTCP("localhost", 3000, AgentRunFactory())

	reactor.run()
