[Twisted-Python] Client Prompt
Daniel Henrique Debonzi
debonzi at gwyddion.com
Mon Feb 16 18:47:47 MST 2004
Hi everybody,
Maybe this is a very stupid question, but I realy couldn't find a way to
solve it by myself.
Would be enough for my aplication if this example works.
So, I want to have a client that read a string from the stdin and then
send it to the server. Wich changes should I do in this code to this
client work like a discrebed
#################################################################
from twisted.internet import reactor, protocol
class EchoClient(protocol.Protocol):
def connectionMade(self):
"""I don't want to write it here
I want to take data from stdin and send o server,
but were and how to do it? Too much dificult?
"""
self.transport.write("hello, world!")
def dataReceived(self, data):
print data
def connectionLost(self, reason):
print "connection lost"
from twisted.internet import reactor
reactor.stop()
class EchoFactory(protocol.ClientFactory):
protocol = EchoClient
def clientConnectionFailed(self, connector, reason):
print "Connection failed - goodbye!"
reactor.stop()
def clientConnectionLost(self, connector, reason):
print "Connection lost - goodbye!"
reactor.stop()
def main():
f = EchoFactory()
reactor.connectTCP("localhost", 5555, f)
reactor.run()
if __name__ == '__main__':
main()
#################################################################
Thanks for all
--
Daniel Henrique Debonzi Linux user number 166903
Gwyddion Embedded Free-Software Development
www.gwyddion.com
São Carlos, São Paulo
Brazil
More information about the Twisted-Python
mailing list