【发布时间】:2017-09-20 19:45:09
【问题描述】:
您好,我在后端使用Tornado、Django 框架来处理前端的套接字消息。我对我的项目不太熟悉,但我的项目中有一个文件,其中有实现websocket.WebSocketHandler 和web.Application 的类。这是此文件的一部分
class Application(web.Application):
"""
Main Class for this application holding everything together.
"""
def __init__(self):
PROJECT_NAME = os.path.basename(os.getcwd())
os.environ['DJANGO_SETTINGS_MODULE'] = PROJECT_NAME + 'tutorial/settings'
# Handlers defining the url routing.
handlers = [
('/room', SocketHandler),
('/room/([a-zA-Z0-9|=%]*)$', SocketHandler),
('/video_call', VideoCallSocketHandler),
('/video_call/([a-zA-Z0-9|=%]*)$', VideoCallSocketHandler),
]
在前端部分是一个函数:
var ws = new WebSocket('wss://domain.com:9003/video_call/' + conferenceId);
ws.onmessage = function (ev) {
window.location.replace(redirectUrl);
};
我相信这个函数会从我们的移动应用程序中获取消息。
所以问题是我想从我的 python 视图发送消息到这个 url 或 'wss://domain.com:9003/video_call/' + conferenceId。
例如:
def some_view_function(request, **kwargs):
conference_id = request.GET.data['conferenceId']
...
if something:
send message to wss://domain.com:9003/video_call/' + conference_id
我该怎么做?
【问题讨论】:
标签: python django websocket tornado