赞助连接

赞助连接

阅 读 文 章

关于twisted 框架中的疑问

[来源:网上转载 (http://bbs.chinaunix.net) | 作者:网友(网络转载) | 时间:2008-06-14 | 浏览: 人次 ]

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


TAG标签 : 疑问 框架 关于 self def from import self.getId data

最新评论 共有0位网友发表了评论

发表评论

评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名:(注册)
密码:
验证码:
匿名发表
网站地图友情连接交流论坛网站投稿广告服务联系我们留言本站长统计
Some rights reserved: www.newhtm.com, 鄂ICP备07010232号 E-mail:chinakafei@live.com,QQ:552766
中国咖啡技术网(Chmhome):国外编程技术书籍,中文编程手册,经典编程文章,交流技术,技术软件下载,计算机论文,毕业论文.