[英]minimal socket server written in python for openshift
I would like to create a minimal socket server written in python that I can run with my OpenShift account. 我想创建一个用python编写的最小套接字服务器,我可以用我的OpenShift帐户运行。 I searched more than a day, found lots of libraries(tornado, django, twisted, flask, autobahn, gevent) that could be used for this, but I could not manage to implement it for me.
我搜索了一天多,发现了很多可用于此的图书馆(龙卷风,django,twisted,flask,autobahn,gevent),但我无法为我实现它。 (Actually I do not really know the differences between these.) I looked for lots of tutorials as well, I found an implementation using Tornado:
(实际上我真的不知道它们之间的区别。)我也找了很多教程,我找到了一个使用Tornado的实现:
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornado.template
class MainHandler(tornado.web.RequestHandler):
def get(self):
loader = tornado.template.Loader(".")
self.write('hello world')
class WSHandler(tornado.websocket.WebSocketHandler):
def open(self):
print 'connection opened...'
self.write_message("The server says: 'Hello'. Connection was accepted.")
def on_message(self, message):
self.write_message("The server says: " + message + " back at you")
print 'received:', message
def on_close(self):
print 'connection closed...'
application = tornado.web.Application([
(r'/ws', WSHandler),
(r'/', MainHandler),
(r"/(.*)", tornado.web.StaticFileHandler, {"path": "./resources"}),
])
if __name__ == "__main__":
application.listen(8000)
tornado.ioloop.IOLoop.instance().start()
However I cannot connect to it from a simple html5 websocket client, furthermore I get 503 Service Temporarily Unavailable
when I enter my domain. 但是我无法从一个简单的html5 websocket客户端连接到它,而且当我进入我的域时,我得到
503 Service Temporarily Unavailable
。
Could you please either give me a minimal implementation (if possible using tornado, or maybe django) that works if upload it to OpenShift or link me a trustworthy and 100% reliable tutorial? 你能不能给我一个最小的实现(如果可能的话,使用龙卷风,或者可能是django),如果将它上传到OpenShift或链接我一个值得信赖和100%可靠的教程? I would be really pleased I can't get my head around this.
我会很高兴我无法理解这一点。
You cannot use port address on openshift like that, I suggest you to do this: 你不能在openshift上使用端口地址,我建议你这样做:
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
application.listen(port , ip)
tornado.ioloop.IOLoop.instance().start()
Check this repo for example: https://github.com/avinassh/openshift-tornado-starter 检查此repo例如: https : //github.com/avinassh/openshift-tornado-starter
It doesn't look like OpenShift lets you just run an application like that. 它看起来不像OpenShift让你只运行这样的应用程序。 You can see a howto guide here: https://github.com/giulivo/openshift-hellotornado
你可以在这里看到如何指导: https : //github.com/giulivo/openshift-hellotornado
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.