我正在使用ws4py/cherrypy进行Websockets支持,并希望在其顶部实现Wamp。
我想到了使用Autobahn,但它似乎仅支持扭曲和异步。
可以使用AutoBaHn功能扩展WS4PY,还是有其他方法?
@oberstet是正确的。这是关于如何运行樱桃应用程序的快速展示:
import cherrypy
from twisted.web.wsgi import WSGIResource
from twisted.internet import reactor
# Our CherryPy application
class Root(object):
@cherrypy.expose
def index(self):
return "hello world"
# Create our WSGI app from the CherryPy application
# it will respond to the /blog path
wsgiapp = cherrypy.tree.mount(Root(), '/blog', {'/': {'tools.etags.on': True}})
# Configure the CherryPy's app server
# Disable the autoreload which won't play well
cherrypy.config.update({'engine.autoreload.on': False})
# We will be using Twisted HTTP server so let's
# disable the CherryPy's HTTP server entirely
cherrypy.server.unsubscribe()
# If you'd rather use CherryPy's signal handler
# Uncomment the next line. I don't know how well this
# will play with Twisted however
#cherrypy.engine.signals.subscribe()
# Tie our app to Twisted
reactor.addSystemEventTrigger('after', 'startup', cherrypy.engine.start)
reactor.addSystemEventTrigger('before', 'shutdown', cherrypy.engine.exit)
resource = WSGIResource(reactor, reactor.getThreadPool(), wsgiapp)
假设您将此片段保存到一个称为" cptw.py"的模块中
twistd -n web --wsgi cptw.wsgiapp
这与扭曲的13.2和Cherrypy 3.2.6
正如您已经注意到的那样,Autobahn | Python支持在扭曲或Asyncio下运行。它包括一个功能齐全的Websoket实施,最重要的是。因此,无需WS4PY,我们没有计划移植Autobahn | Python包含WS4PY的WAMP层。
Twisted还支持运行任何符合WSGI的应用程序。因此,原则上,您应该能够在扭曲的下旋转樱桃。我尚未测试 - 我仅在扭曲上测试(并经常使用)烧瓶。