minimal socket server written in python for openshift -
i create minimal socket server written in python can run openshift account. searched more day, found lots of libraries(tornado, django, twisted, flask, autobahn, gevent) used this, not manage implement me. (actually not know differences between these.) looked lots of tutorials well, found implementation using 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 accepted.") def on_message(self, message): self.write_message("the server says: " + message + " @ 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 cannot connect simple html5 websocket client, furthermore 503 service temporarily unavailable
when enter domain.
could please either give me minimal implementation (if possible using tornado, or maybe django) works if upload openshift or link me trustworthy , 100% reliable tutorial? pleased can't head around this.
you cannot use port address on openshift that, suggest this:
ip = os.environ['openshift_python_ip'] port = int(os.environ['openshift_python_port']) application.listen(port , ip) tornado.ioloop.ioloop.instance().start()
check repo example: https://github.com/avinassh/openshift-tornado-starter
Comments
Post a Comment