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. 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. (Actually
I do not really know the differences between these.) I looked for lots of
tutorials as well, I found an 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 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.
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? I would be really
pleased I can't get my head around this.
No comments:
Post a Comment