gpt4 book ai didi

javascript - 如何通知客户端浏览器有关服务器上的某些事件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:06 25 4
gpt4 key购买 nike

我在服务器端使用 python (Tornado),在客户端使用一些 javascript。我有常见的情况 - 一个用户向另一个用户发送消息。我希望服务器将新消息通知客户端的浏览器(消息的接收者)。我该怎么做?我应该与客户端建立长期连接(可能使用 websocket)还是其他方式?

附言为了通过 websocket 建立连接,我找到了很好的库 TornadIO

PS2因此,由于在 betwebb 服务器和每个客户端之间建立连接的项目负载很高,因此看起来很可疑。我怕c10k的问题。可能这只是我缺乏知识。

最佳答案

I'm using python (Tornado) on server side and some javascript on a client side. I have the common situation - one user send a message to another. And I want server to notify client's browser (reciever of the message) about new message. How can I do it? Should I establish long-alive connection with client (maybe using websocket) or something else?

使用实时网络服务器,例如 Tornado - 是的。 TornadIO 看起来是一个很好的解决方案,因为它将使用 socket.io,它具有适用于旧版浏览器的回退选项。

Wikipedia entry on the C10k issues提供已解决此问题的服务器列表:

A few web servers have been developed to counter the C10K problem:

  • nginx, which relies on an event-driven (asynchronous) architecture, instead of threads, to handle requests (WordPress.com uses nginx to solve the C10K problem)[2]
  • Lighttpd, which relies on an asynchronous architecture to handle requests[3]
  • Cherokee, a lightweight web server[4]
  • Tornado, a non-blocking web server and web application framework[5] written in Python
  • Apache Deft, asynchronous, non-blocking web server running on the JVM
  • JBoss Netty, a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients[6]
  • Node.js, asynchronous, non-blocking web server running on Google's V8 JavaScript engine[7]
  • EventMachine, an asynchronous, non-blocking web server running on Ruby EventMachine
  • Yaws, a web server written in Erlang; profiting from Erlang's extremely lightweight processes.
  • Medusa, a non-blocking web server library written in Python

如您所见,列出了 Tornado。

除此之外,您的问题可能更多关于 horizontal scaling而不是关于如何实现服务器到客户端的通知。

取决于哪个realtime server solution你选择这可能永远不会成为问题。例如,Caplin System's Liberator 的单个实例可以实现超过 10,000 个持久连接。

关于javascript - 如何通知客户端浏览器有关服务器上的某些事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8199683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com