在没有websocket的Django中保持连接打开

编程入门 行业动态 更新时间:2024-10-27 22:20:56
本文介绍了在没有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中保持连接打开

本文发布于:2023-11-06 17:50:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:websocket   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!