All pastes #716182 Raw Edit

chat server

public python v1 · immutable
#716182 ·published 2007-09-26 16:30 UTC
rendered paste body
from twisted.internet import reactorfrom twisted.internet.protocol import Protocol, ClientFactoryfrom twisted.protocols.basic import LineReceiverfrom Tkinter import *from twisted.internet import tksupportconexion = 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()