关于twisted 框架中的疑问

关于twisted 框架中的疑问

from twisted.internet.protocol import Factory
from twisted.protocols.basic import LineOnlyReceiver
from twisted.internet import reactor

class Chat(LineOnlyReceiver):
    def lineReceived(self,data):
        self.factory.sendAll("%s :%s" % (self.getId(), data))

    def getId(self):
        return str(self.transport.getPeer())

    def connectionMade(self):
        print "New commectioin from",self.getId()
        self.transport.write("Welcome to the chat server , %s\n" % self.getId())
        self.factory.addClient(self)

    def connectionLost(self,reason):
        self.factory.delClient(self)

class ChatFactory(Factory):
    protocol = Chat

    def __init__(self):
        self.clients = []

    def addClient(self,newclient):
        self.clients.append(newclient)

    def delClient(self, message):
        for proto in self.clients:
            proto.transport.write(message + "\n")

reactor.listenTCP(5000, ChatFactory())
reactor.run()

____________
以上代码用为服务端运行后为什么sendAll不能正常工作,总是报错,或者哪位能帮我编个跟他配套的client
你需要为ChatFactory实现sendAll方法
已经解决;
但是还是有很疑问,比如服务端client是什么东东?信息的最大尺度?另外最重要是dataReceived与lineReceived的区别,因为我是客户端是用flex做的,现在对dataReceived支持很好,要如何才能支持lineReceived呢?希望有高人指点

#!/usr/local/python25/bin/python
#-*- encoding:gb2312 -*-

"""
Socket example server using Twisted. chat server test

@author: U{Nick Royce<mailto:ilikedesign2003@yahoo.com.cn>}

@time:2008/6/15
"""

from twisted.internet import protocol
from twisted.protocols import basic
from twisted.python import log
from twisted.internet import reactor
import sys
import pyamf

class ConfigServer(basic.LineReceiver):
    encoding = pyamf.AMF0
   
    def __init__(self):
        self.encoder = pyamf.get_encoder(self.encoding)
        self.stream = self.encoder.stream

    def dataReceived(self, data):
        print "data : " + data
        if data == 'quit':
            self.sendLine("Good bye!")
            self.transport.loseConnection()
        else:
            self.broadcast(data)
   
    def broadcast(self, msg):
        for client in self.factory.clients:
            client.sendLine(msg);

    def connectionMade(self):
        self.factory.clients.append(self)
        print "Connect from %s.." % self.transport.getHost()
        self.sendLine("Welcome...%s" % self.transport.getHost())

    def connectionLost(self, reason):
        self.broadcast("Disconnect...")
        self.factory.clients.remove(self)
        pass

class ConfigServerFactory(protocol.ServerFactory):
    protocol = ConfigServer
    clients = []

def main():
    log.startLogging(sys.stdout)
    reactor.listenTCP(8080,ConfigServerFactory())
    reactor.run()
   
if __name__ == '__main__':      
    main()

没用过。
谢谢各位回贴,特别是shhgs .

多问一句,关于在twisted如果想客户端调服务端的方法,或是服务端调用客户端要如何操作呢.或是不走twisted这条路了.