如何避免彗星聊天中的死消息?

发布于 2024-07-26 09:52:18 字数 220 浏览 0 评论 0原文

我正在用 Erlang 和 PHP 进行 Comet 聊天。 但现在我想我遇到了一个问题:轮询连接会在大约一定时间(我设置为10秒)内自动断开并重新连接,因此会有一段时间用户无法连接到聊天服务器。 如果此时用户发送消息,该消息就会死掉(没有人可以接收到它)。

在客户端代码中,我使用 jquery 和 jsonp 来实现轮询连接。 有什么好的办法解决这个问题吗?

先谢谢啦~

I am doing Comet chat with Erlang and PHP. But now I think I met a problem: the polling connection will disconnect and reconnect automatically in about a certain time (I set this with 10 seconds), so there will be a period of time that the user doesn't connect to chat server. If a user send message at that time, the message will be dead (no one could receive it).

In the client code I am using jquery with jsonp to realize the polling connection. Is there any good way to solve this problem?

Thanks in advance~

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

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

发布评论

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

评论(3

内心激荡 2024-08-02 09:52:18

您可以有两个并发连接; 将它们交错排列,以便一个在连接(并将用户的消息推送到服务器),而另一个在监听。

You're allowed two concurrent connections; interleave them, so that one is connecting (and pushing the user's messages to the server) while the other is listening.

秋千易 2024-08-02 09:52:18

在服务器上有一个会话进程,用于在客户端未连接时存储所有消息。 如果客户端在一段(可配置的)时间内没有连接,会话可能会终止。 当客户端连接时,会话可以将所有排队的消息发送到该连接。

Have a session process on the server that stores all messages while the client isn't connected. If the client doesn't connect for some (configurable) time, the session can die. When the client does connect, the session can send all queued messages to the connection.

行至春深 2024-08-02 09:52:18

当发送消息时,只需让 jquery 立即重新连接并在发送消息时发送消息。

When a message is sent, just have jquery reconnect immediately and send the message when it does so.

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