How to write a Twisted client plugin
Should you perhaps be using the tac
files to run it from command line?
http://twistedmatrix.com/documents/12.2.0/core/howto/application.html#auto5
Then using your MyChat
class should be easier in another program...
You have to return a main service object from your MyServiceMaker().makeService
method. Try adding from twisted.internet import service
then in makeService
add this at the beginning: top_service = service.Multiservice()
Create the TCPServer service: tcp_service = TCPServer(...)
Add it to the top service: tcp_service.setServiceParent(top_service)
Then return the top service: return top_service
You may also need to take a look at this excellent series of tutorials from Dave Peticolas (article n°16 is the one which is useful for your problem)
Just follow this links for docs and help:
from __future__ import print_functionfrom twisted.internet import reactorfrom twisted.web.client import Agentfrom twisted.web.http_headers import Headersagent = Agent(reactor)d = agent.request( 'GET', 'http://example.com/', Headers({'User-Agent': ['Twisted Web Client Example']}), None)def cbResponse(ignored): print('Response received')d.addCallback(cbResponse)def cbShutdown(ignored): reactor.stop()d.addBoth(cbShutdown)reactor.run()
Output:
C:\Python27>python.exe twist001.pyResponse received