cherrypy作为gevent-socketio服务器 [英] cherrypy as a gevent-socketio server

查看:100
本文介绍了cherrypy作为gevent-socketio服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用gevent-socketio,这太好了!

I have just started using gevent-socketio and it's great!

但是我一直在使用聊天教程中的默认socketioserversocketio_manage,并且想知道如何将socketiocherrypy集成.

But I have been using the default socketioserver and socketio_manage from the chat tutorial and was wondering how to integrate socketio with cherrypy.

本质上,我该如何解决这个问题:

essentially, how do I turn this:

class MyNamespace(BaseNamespace):...

def application(environ, start_response):
    if environ['PATH_INFO'].startswith('/socket.io'):
        return socketio_manage(environ, { '/app': MyNamespace})
    else:
        return serve_file(environ, start_response)

def serve_file(...):...

sio_server = SocketIOServer(
    ('', 8080), application, 
    policy_server=False) sio_server.serve_forever()

变成普通的cherrypy server?

推荐答案

Gevent-socketio基于Gevent和Gevent的Web服务器.有两种实现:pywsgi(是纯python)和wsgi(使用libevent的http实现).

Gevent-socketio is based on Gevent, and Gevent's web server. There are two implementations: pywsgi, which is pure python, and wsgi, which uses libevent's http implementation.

在此处查看以"pywsgi.WSGIServer和wsgi.WSGIServer之间的区别"开头的段落:

See the paragraph starting with "The difference between pywsgi.WSGIServer and wsgi.WSGIServer" over here:

http://www.gevent.org/servers.html

从某种意义上说,这些服务器是绿色"的,因为它们将控制权交给了Gevent循环.因此,您只能在afaik上使用这些服务器.这样做的原因是服务器位于请求的最开始,并且将知道如何处理升级"和Websockets协议协商,并且它将在环境"内部传递值,该值用于下一层(SocketIO)会期望并知道如何处理.

Only those servers are "green", in the sense that they yield the control to the Gevent loop.. so you can only use those servers afaik. The reason for this is that the server is present at the very beginning of the request, and will know how to handle the "Upgrade" and websockets protocol negotiations, and it will pass values inside the "environ" that the next layer (SocketIO) will expect and know how to handle.

您还需要使用gevent-websocket软件包.因为它是绿色的(而gevent-socketio是基于该软件包的).您不能只交换websocket堆栈.

You will also need to use the gevent-websocket package.. because it is green (and gevent-socketio is based on that one). You can't just swap the websocket stack.

希望这会有所帮助.

这篇关于cherrypy作为gevent-socketio服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆