如何通知用户另一位已上线?

发布于 2024-07-19 05:59:14 字数 374 浏览 4 评论 0原文

我正在使用雅虎通与朋友聊天。 每当我的朋友上线(几乎是中间)时,YM 都会通知我。 雅虎怎么样了! (和其他公司)如何实施这一点? 据我猜测,有一些技术可以解决这个问题:

  • 拉:客户端不断地(可能持续 500 毫秒)询问服务器哪些用户(在用户列表中)刚刚上线然后通知用户。

  • 推送:服务器判断哪些用户上线,然后向客户端发送通知。

第二种方法更容易被接受。 用户的数据可能包含他的朋友的列表(将他添加到他们的列表中),并且引发登录事件,服务器应用程序将向该列表中的所有用户发送通知消息。

好吧,这只是我的猜测。 现实中是如何实施的呢? 你能告诉我吗?

谢谢。

I'm using yahoo messenger to chat with my friends. Every time a friend of mine comes online (almost intermediately) YM will notify me. How did Yahoo! (and other companies) do to implement this? As far as I guess, there are some techniques to solve this issue:

  • Pulling: client constantly (500ms duration, maybe) asks server about which users (in the user's list) has just come online and then notify user.

  • Pushing: server determines which users come online and then send a notify to client.

The second approach is much more acceptable. The data of user may contain a list of his friend (who added him to their lists), and the login event raises, server app will send a notify message to all users in this list.

OK, this is only my guess. How was it implemented in reality? Can you tell me?

Thank you.

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

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

发布评论

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

评论(8

夏末 2024-07-26 05:59:14

服务器正在将数据下推。 服务器有您的朋友列表,更重要的是您所在的列表。 当您登录时,它会查看第二个列表并将消息推送到每个连接的客户端。 这真的很简单。 查看 Pidgin 的源代码 ( pidgin.im ) 了解更具体的实现细节。

the server is pushing the data down. the server has a list of your friends, and more importantly a list of whose list you're on. when you sign on, it looks through that second list and pushes a message to each client that's connected. it's pretty simple really. take a look at Pidgin's source code ( pidgin.im ) for more specific implementation details.

说谎友 2024-07-26 05:59:14

我建议使用 Wireshark 或任何其他网络流量检查器来准确查看 Yahoo Messenger 运行时发生的情况。

I suggest using Wireshark or any other network traffic inspector to see exactly what's happening on Yahoo Messenger while it's running.

耳根太软 2024-07-26 05:59:14

应该是“推式架构”。

服务器无法容忍大量用户的持续拉动。

Should be "push architecture".

Servers can't tolerate constant pulling for lots of user.

孤独患者 2024-07-26 05:59:14

可能是长期存在的 HTTP 请求。 IM 客户端调用服务器上的 HTTP 方法,但服务器在有更新之前不会响应。 此时,它会响应“更新”,然后 IM 客户端调用另一个 HTTP 方法来获取更新。

真正的推送是不可能的,因为互联网上的许多(大多数?)人都在 NAT 路由器后面。

Possibly long lived HTTP requests. The IM client calls to a HTTP method on the server but the server doesn't respond until there is an update. At that point it responds with "update" and the IM client then calls another HTTP method to get the update.

Real push isn't possible because many (most?) people on the Internet are behind NAT routers.

欢烬 2024-07-26 05:59:14

它使用与 Buddy Check 类似的技术,但仅让您知道如果用户想让你知道。 但好友检查实际上为您提供了真实的真相。

It uses a similar technology as Buddy Check, but only lets you know if the user wants you to know. But Buddy Check actually gives you the real truth.

醉南桥 2024-07-26 05:59:14

我同意其他人的观点,你可以自己检查源代码或网络数据包,但从另一个角度思考:当你有数十万用户而大多数用户可能只有几十个“好友”时,哪种方法更有意义?

  1. 每隔几秒钟就有数十万用户 ping 您的服务器 = 大量负载
  2. 当朋友的状态发生变化时向客户端推送更新,这种情况发生的规模可能要小得多 - 每隔几分钟进行一些更新。

I agree with others that you could just examine the source code or network packets yourself, but think about it from another perspective: which approach makes more sense when you have hundreds of thousands of users and most users probably have just a few dozen "buddies"?

  1. Have hundreds of thousands of users pinging your servers every few seconds = lots of load
  2. Push out updates to clients when their friend's statuses change, which likely happens on a much much smaller scale - a few updates every few minutes.
天涯离梦残月幽梦 2024-07-26 05:59:14

当您登录时,雅虎会向列表中同时在线的每个人发送(推送)“在线事件”。 如果连接是通过 HTTP 进行的,则您和 Yahoo 的服务器之间会进行 ping/pong 交换以保持连接处于活动状态 (wikipedia) - 允许通过 NAT 等进行推送。 否则,TCP/IP 连接在您登录期间将保持活动状态。 如果 ping/pong 不成功(您会假设经过多次重试),雅虎服务器会向您的所有在线朋友发送(推送)消息,通知他们“离线事件”。

所以回答你的问题,这是一个推动。

When you login, Yahoo sends (pushes) an 'online event' to everyone on your list who is also online. If the connection is over HTTP, there is a ping/pong exchange between you and Yahoo's server to keep the connection alive (wikipedia) - which allows this push to happen through NATs and whatnot. Else, a TCP/IP connection is kept alive for the duration of your login. If the ping/pong isn't successful (after a number of retries, you would assume), the Yahoo server sends (pushers) messages to all your online friends notifying them of the 'offline event'.

So to answer you question, it is a push.

耀眼的星火 2024-07-26 05:59:14

我知道 gmail 上的 gtalk 和 facebook 使用 comet。 这看起来是一个很好的技术,但它很昂贵。 这是关于 PHP 的很好的教程

I know gtalk over gmail and facebook uses comet. this looks like a good technique but its expensive. this is a good tutotial about in PHP

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