from twisted.internet import reactor from twisted.internet.protocol import Protocol, ClientFactory from twisted.protocols.basic import LineReceiver from Tkinter import * from twisted.internet import tksupport conexion = None class ChatClient(LineReceiver): def __init__(self): global conexion if conexion is None: conexion = self else: print "Hay mas de una conexion! Esto no deberia pasar... :-(" def connectionMade(self): self.sendLine("Hello server") def lineReceived(self, line): print line def connectionLost(self, reason): pass class ChatFactory(ClientFactory, ): protocol = ChatClient def clientConnectionFailed(self, connector, reason): reactor.stop() def clientConnectionLost(self, connector, reason): reactor.stop() def sendMessage(): conexion.sendLine("Test") chat = ChatFactory() root = Tk() b1 = Button(root,text="Send") b1.configure(command=sendMessage) b1.pack() tksupport.install(root) reactor.connectTCP('localhost',8007,chat) reactor.run()