我正在努力学习Twisted,无意中发现了一些我不太喜欢的东西——“Twisted命令提示符”。我在Windows机器上摆弄Twisted,并尝试运行“聊天”示例:from twisted.protocols import basic
class MyChat(basic.LineReceiver):
def connectionMade(self):
print "Got new client!"
self.factory.clients.append(self)
def connectionLost(self, reason):
print "Lost a client!"
self.factory.clients.remove(self)
def lineReceived(self, line):
print "received", repr(line)
for c in self.factory.clients:
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
我用谷歌搜索过,但搜索词似乎太模糊,无法返回任何有意义的回复。
谢谢。