apache - Apache2.4 + WSGI + Bottle + Websocket + 烧杯
问题描述
如标题所示,我在Ubuntu20服务器上使用Apache2.4、WSGI和Bottle。
我已使用此文件成功设置了端点:
"""file: app.py"""
import os, sys
from bottle import app, get, post, request, route, template
from beaker.middleware import SessionMiddleware
os.chdir(os.path.dirname(__file__))
sys.path.append(os.path.dirname(__file__))
application = SessionMiddleware(app())
@route('/<query>')
def index(query):
return f"Hello, you entered: {query}"
Apache conf 文件包含以下条目:
WSGIScriptAlias /test /path/to/my/project/app.py
这样当我调用该站点时,http://<ip_addr>/test
我可以在页面上看到响应。
现在我想在同一台服务器上设置一个 websocket 端点。
谁能告诉我应该怎么做才能使用此代码(基于前面的示例):
"""file: ws.py"""
# taken from https://github.com/zeekay/bottle-websocket
import os, sys
from bottle import app, get, post, request, route, template
from beaker.middleware import SessionMiddleware
from bottle.ext.websocket import GeventWebSocketServer
from bottle.ext.websocket import websocket
#os.chdir(os.path.dirname(__file__))
sys.path.append(os.path.dirname(__file__))
application = SessionMiddleware(GeventWebSocketServer) # is tis correct???
@get('/websocket', apply=[websocket])
def echo(ws):
while True:
msg = ws.receive()
if msg is not None:
ws.send(msg)
else: break
我需要 Apache conf 文件中的相应条目吗?喜欢:
WSGIScriptAlias /ws /path/to/my/project/ws.py
谁能告诉我我应该怎么做才能使 websocket 以与以前的端点类似的方式工作?
解决方案
推荐阅读
- vespa - 使用继承的结构数组属性对搜索进行排名
- python - Python中的两个单双引号
- angular - ag 网格快速水平滚动导致某些列未显示
- vb.net - 当用户在文本框控件上按 Enter 时,如何抑制烦人的哔哔声?
- java - Android sqlite - 如何计算sqlite中2个REAL条目之间的差异?
- javascript - 数组迭代期间的addEventListener问题[已解决]
- javascript - 如何在解决之前等待承诺中的所有代码完成?(但有点复杂)
- java - 使用 makefile 时找不到或加载主类错误
- javascript - 对象和属性的随机数组
- javascript - 更改数据后,如何在 Realm Javascript 中获取旧的修改值