本文整理汇总了Python中twisted.internet.protocol.Factory.users方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.users方法的具体用法?Python Factory.users怎么用?Python Factory.users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.Factory
的用法示例。
在下文中一共展示了Factory.users方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startService
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import users [as 别名]
def startService(textbuffer, port, welcome, statusbar):
addText(textbuffer, APP_NAME, LOG_INFO)
addText(textbuffer, _("Version ") + APP_VERSION, LOG_INFO)
addText(textbuffer, _("Attempting to start server at port ") + str(port) + "\n", LOG_INFO)
addText(textbuffer, _("Creating Factory"), LOG_INFO)
factory = Factory()
factory.protocol = RPG
factory.textbuffer = textbuffer
factory.statusbar = statusbar
factory.clients = []
addText(textbuffer, _("Saving welcome message..."), LOG_INFO)
factory.welcome = welcome
f = open(PATH_WELCOME_MSG, "w")
f.write(welcome)
f.close()
addText(textbuffer, _("Setting up Users datastructure"), LOG_INFO)
factory.users = Users()
addText(textbuffer, _("Listening for incoming connections..."), LOG_INFO)
reactor.listenTCP(port, factory)
reactor.run()
示例2: TinyFileSlave
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import users [as 别名]
class TinyFileSlave(Protocol):
"""Slave server — currently just echos the result onto console."""
def connectionMade(self):
print "Master server connected"
def connectionLost(self, reason):
print "Master server disconnected"
def dataReceived(self, data):
"""We've gotten a request. It comes in a protocol buffer form."""
# get the request protocol buffer
print "Received data"
info = FileRequest()
info.ParseFromString(data)
print "Filename:", info.filename
print "Request type:", info.request_type
print "File contents:", info.contents
factory = Factory()
factory.users = {}
factory.protocol = TinyFileSlave
reactor.listenTCP(1112, factory)
print "TinyFile server started"
reactor.run()