def main():
"""
Loads the registered-widgets file.
Opens up ServerFactory to listen for requests on the specified port.
"""
open(REGISTERED_FILE, 'a').close() # touch the file so that it exists
with open(REGISTERED_FILE, 'r') as f:
for line in f:
line = line.strip()
# Skip lines that start with '#' so that we can comment-out lines
if line.startswith('#'): continue
print "Loading line: '%s'" % line
new_widget = Widget(json_str=line)
if new_widget.device_id in REGISTERED_DEVICES:
print "Skipping duplicate device ID %s" % repr(new_widget.device_id)
else:
REGISTERED_DEVICES[new_widget.device_id] = new_widget
factory = protocol.ServerFactory()
factory.protocol = DoorServer
print "Starting DoorApp server listening on port %d" % PORT
reactor.listenTCP(PORT, factory)
reactor.run()
server.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录