Hi Tim,
I think you need to keep a reference to an instance of your
MyClientProtocol. Your example does not show how you actually connected
your bot to a server but I assume it follows on the call to load_config on
startService. One way to do this:
class MyService(Service):
def __init__(self):
self._client = None
def clientConnected(self, prot):
# set reference to the protocol instance
self._client = prot
def startService():
self.config = load_config(config_file)
# connect bot to the server
f = MyClientFactory(self)
reactor.connectTCP(self.config.host, self.config.port, f)
def sendMessage(self, msg):
if self._client:
self._client.sendLine(msg)
Client reference can be set from the protocol instance when connection has
been made:
class MyClientProtocol(protocol.Protocol):
#
def connectionMade(self):
self.factory.service.clientConnected(self)
HTH,
Enrique
Post by Tim HughesWoops : accidentally sent too early
Hi all,
I am looking into twisted for writing a client application (bot style) and
most of the examples I find are for server style applications.
Looking at the finger example and
https://github.com/jdavisp3/twisted-intro/blob/master/twisted-server-3/fastpoetry.py
I am just wondering where is best to put my application logic.
The protocol is basically a ascii line style application
It feels to me that my Service should be the main business logic and the
protocol should just be a simple send/receive something like this gist
https://gist.github.com/timhughes/f85da0c2d88ecb4ab5e3#file-twisted_application_client-py-L36
I was then planning on writing web interface that interacted with the
service to send messages and display the response.
My main issue here is how to send the message from the service via the
protocol. I cannot find any good examples of this and am beginning to think
I am conceptualising incorrectly or over thinking it. If anyone can point
me to some examples or point me in the right direction it would be awesome.
Hopefully my example makes sense.
Cheers
Tim
Tim Hughes
Hi all,
I am looking into twisted for writing a client application (bot style) and
most of the examples I find are for server style applications.
Looking at the finger example and
https://github.com/jdavisp3/twisted-intro/blob/master/twisted-server-3/fastpoetry.py
I am just wondering where is best to put my application logic.
The protocol is basically a ascii line style application
It feels to me that my Service should be the core and the protocol should
just be something like
Tim Hughes
_______________________________________________
Twisted-Python mailing list
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python