打开到服务器的 TCP 流的最佳方式是什么?

发布于 2024-11-04 08:04:21 字数 391 浏览 0 评论 0原文

这是一个很难确定的问题,但基本上我想知道最好的方法是什么(不是“你的意见是什么”,而是“这将最充分地满足我将提出的要求”)是从客户端打开流连接我认为这个术语是 HTTP 绑定与 HTTP 轮询,这里的上下文是一个聊天应用程序 - 我想要一个流式连接,以便浏览器不会不断地推送请求。这里的客户端是 KnockoutJS 和 jQuery。我希望能够以 JSON 形式来回推送数据(或者至少可以由 jQuery 和 Knockout 的 toJSON 进行操作)。确定它会是什么,但我可能会在 Linux 服务器上运行,所以任何与之兼容的东西都可以正常工作。 如果我可以提供更多详细信息,请告诉我 - 我确信我遗漏了一些明显的细节。另外,我知道这可能有一个重复的问题,所以如果你的答案就像关闭一个骗局并添加一个链接一样好,那就太好了。 谢谢!

Rather a hard to nail down question, but basically I'm wondering what the best way (and not "what's your opinion" but "which will most adequately meet the requirement i shall set forth) is to open a stream connection from a client side webpage to a server such that either can send data to the other without polling? I'm thinking the term for this is HTTP binding vs. HTTP Polling. The context here is a chat application - i'd like a streamed connection so that the browser isn't constantly pushing requests out. The client end here is KnockoutJS and jQuery. I'd like to be able to have the data pushed back and forth be JSON (or at least manipulatable by jQuery and Knockout's toJSON). The server end - not quite sure what it is going to be, but i'll probably be running on a linux server, so anything compatible with that works fine.
If there's any more details i can provide, just let me know - i'm sure i left some obvious detail out. Also, i'm aware there's probably a duplicate question on this, so if your answer is as good as closing for a dupe and putting in a link, that's great.
Thanks!

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

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

发布评论

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

评论(1

小姐丶请自重 2024-11-11 08:04:21

我认为你正在寻找的东西被称为彗星。基本思想是让 HTTP 请求保持较长时间的打开状态,以便服务器可以在数据到来时将数据发送到客户端,而不是客户端必须不断轮询服务器以获取新数据。有多种方法可以实现它。这篇维基百科文章是了解更多信息的良好开端。

MIX 2011 视频讨论了长轮询技术(尽管视频中的建议是Web 套接字将是未来浏览器的更好解决方案)。

I think what you're looking for is referred to as Comet. The basic idea is to keep HTTP requests open for longer periods of time so that the server can send data to the client as it comes in, rather than the client having to continually poll the server for new data. There are multiple ways to implement it. This Wikipedia article is a good start for more info.

This MIX 2011 video discusses the long polling technique (although the suggestion in the video is that web sockets will be a better solution with future browsers).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文