Django 有办法打开 HTTP 长轮询连接吗? [英] Does Django have a way to open a HTTP long poll connection?

查看:32
本文介绍了Django 有办法打开 HTTP 长轮询连接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保持连接打开,直到事件发生.

Leave the connection open, until an event occurs.

推荐答案

看看 Django/Comet (Push):最少的罪恶?Python 中 Comet 的最新推荐? - COMET 是ajax 长轮询"的另一个名称.

Have a look at Django / Comet (Push): Least of all evils? or The latest recommendation for Comet in Python? - COMET is another name for "ajax long-polling".

显然,最常见的方法不是直接在 django 中执行,而是在附加守护程序的帮助下进行(可能是因为例如 Apache 不能很好地处理大量长期连接).现在 nodejs+socketio 在这方面非常流行(它甚至可以使用 WebSockets)——你只需要找到一种在两者之间传递数据的好方法.如果它是单向的(例如只向所有连接的客户端广播),那么 redis pubsub 队列不是一个糟糕的选择.

Apparently the most common approach is not doing it directly in django but with the help of an additional daemon (probably because e.g. Apache doesn't do well with lots of long-living connections). Nowadays nodejs+socketio is pretty popular for this (and it can even use WebSockets) - you just need to find a nice way to pass data between the two things. If it's unidirectional (e.g. just broadcasts to all connected clients) a redis pubsub queue is not a bad option for this.

但是http://code.google.com/p/django-orbited/ 可能是最 djangoish 的解决方案.

But http://code.google.com/p/django-orbited/ is probably the most djangoish solution.

这篇关于Django 有办法打开 HTTP 长轮询连接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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