我正在努力學習Twisted,無意中發現了一些我不太喜歡的東西——“Twisted命令提示符”。我在Windows機器上擺弄Twisted,并嘗試運行“聊天”示例:from twisted.protocols import basic
class MyChat(basic.LineReceiver):
python服務器。def connectionMade(self):
print "Got new client!"
self.factory.clients.append(self)
python scrapy教程、def connectionLost(self, reason):
print "Lost a client!"
self.factory.clients.remove(self)
python 網絡框架,def lineReceived(self, line):
print "received", repr(line)
for c in self.factory.clients:
python socket,c.message(line)
def message(self, message):
self.transport.write(message + '\n')
from twisted.internet import protocol
from twisted.application import service, internet
factory = protocol.ServerFactory()
factory.protocol = MyChat
factory.clients = []
application = service.Application("chatserver")
internet.TCPServer(1025, factory).setServiceParent(application)
但是,要將此應用程序作為Twisted服務器運行,我必須通過“Twisted命令提示符”運行它,命令如下:twistd -y chatserver.py
是否有任何方法可以更改代碼(設置Twisted配置設置等),以便我可以通過以下方式運行它:python chatserver.py
我用谷歌搜索過,但搜索詞似乎太模糊,無法返回任何有意義的回復。
謝謝。
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态