从twisted.web 为twisted.web 站点构建comet 服务器

发布于 2024-09-13 11:52:42 字数 644 浏览 3 评论 0原文

所以我已经建立了一个网站,并且我需要一个用于聊天应用程序的彗星服务器。该网站是用twisted.web构建的,我也想用twisted构建comet服务器,因为我已经对它有些熟悉了。

但我不知道该怎么做。我看过这篇文章 并理解代码片段中的机制——但我尝试了一下,页面需要很长时间才能加载,当它加载时,它已经充满了时间,然后继续添加它们。

我的想法是,我将其作为一个单独的进程运行,然后在另一个进程上运行我的扭曲网站。扭曲站点中的页面将对 comet 服务器进行 ajax 调用,该服务器将等待响应。但是该响应是否会像页面加载一样需要很长时间才能返回?

彗星服务器如何最好地从网站服务器获取数据?它不仅仅会轮询网站,或者我也可能没有 comet 服务器——我是否会在 comet 服务器的 GET 处理程序中放置一个无限循环,然后让网站调用它并中断?彗星服务器和网站如何共享数据?比如,彗星服务器如何知道有关用户会话数据的任何信息——他们是谁,他们在等待什么,它可以发送给他们什么?

另外,我对此也不确定,但是我是否必须将线程合并到彗星服务器中,或者它已经是多线程的了?

So I have a website already set up, and I need a comet server for a chat application. The site is built with twisted.web, and I want to build the comet server with twisted as well since I'm already somewhat familiar with it.

But I'm not sure how to do it. I've looked at this post and understand the mechanics in the code snippet -- but I tried it and the page takes AGES to load, and when it does, it's already full of times, and then continues adding them.

My idea of how this would work is, I would have this running as a separate process, and then run my twisted site on another. A page in the twisted site would have an ajax call to the comet server, which would wait for a response. But would that response take ages to return like the page load did?

And how would the comet server best get data from the website server? It wouldn't just poll the website or I may as well have no comet server -- would I just put an infinite loop in the GET handler for the comet server, and have the website call it and interrupt? How would the comet server and website share data? Like, how would the comet server know anything about a user's session data -- who they are, what they're waiting for, what it can send to them?

Also, I'm not sure about this, but do I have to incorporate threading into the comet server, or is it multithreaded already?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乙白 2024-09-20 11:52:42

您可以使用 Orbited(这是一个基于 Twisted 的 Comet 服务器)并在与 Web 服务器相同的进程中运行它。它非常光滑。您无需使用其内置代理,只需直接使用其内部即可。你会做类似的事情:

from orbited.cometsession import Port
...
reactor.listenWith(Port, factory=someFactoryYouWrote, resource=someResourceYouWrote, childName='tcp')

You can use Orbited (which is a comet server based on Twisted) and run it in the same process as your web server. It's pretty slick. Instead of using its built-in proxy, you just use its guts directly. You'd do something like:

from orbited.cometsession import Port
...
reactor.listenWith(Port, factory=someFactoryYouWrote, resource=someResourceYouWrote, childName='tcp')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文