在没有websocket的Django中保持连接打开 [英] Keeping connection open in Django without websockets

查看:92
本文介绍了在没有websocket的Django中保持连接打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台不支持Websocket的小型计算机,我想从服务器接收推送通知.

I have a mini computer that does not support websockets that I would like to receive push notifications from a server.

问题在于,客户端连接到服务器后,服务器会做出响应,然后关闭连接.这样一来,客户端就必须不断地重新连接到服务器以获取新信息.

The issue is that after the client connects to the server, the server responds and then closes the connection. This makes it so the client has to continually reconnect to the server to get new information.

有没有一种使用Django的方式允许连接保持打开状态,然后让服务器将数据发布到客户端?

Is there a way using Django to allow the connection to be left open and then have the server publish data to the client?

推荐答案

Django主要是一个请求/响应框架,因此不支持真正的双工通信.

Django is primarily a request/response framework and as such does not have support for real duplex communication.

Socket.IO是事实上的库,可以使类似websocket的功能跨浏览器(IE5.5 +),如果浏览器允许,则使用真实的websockets作为传输,回退到HTTP长轮询或其他情况没有.有关将Socket.IO与Django集成的各种选项,请阅读.

Socket.IO is the de facto library that makes websocket-like functionality cross-browser (IE5.5+), using real websockets as a transport if the browser allows it, falling back to HTTP long-polling or whatever else if it doesn't. For various options on integrating Socket.IO with Django, read this.

这篇关于在没有websocket的Django中保持连接打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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