python服務器,python twisted應用_如何通過Python(而不是通過Twisted)運行Twisted應用程序?

 2023-11-18 阅读 30 评论 0

摘要:我正在努力學習Twisted,無意中發現了一些我不太喜歡的東西——“Twisted命令提示符”。我在Windows機器上擺弄Twisted,并嘗試運行“聊天”示例:from twisted.protocols import basicclass MyChat(basic.LineReceiver):python服務器。def connectionMade(

我正在努力學習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

我用谷歌搜索過,但搜索詞似乎太模糊,無法返回任何有意義的回復。

謝謝。

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/177626.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息