如何通知单个用户操作多个客户端?基于Web的渠道

时间:2022-08-26 18:40:00

Lets say we have a web based application where users login to their own channel. And our server manages and maintains a list of users, and their current ip addresses.

假设我们有一个基于Web的应用程序,用户可以登录自己的频道。我们的服务器管理和维护用户列表及其当前的IP地址。

When someone logs in, is it possible for each client to receive a notification of this users login? Equally if someone logs out, a similar notification would be generated. (Useful for maintaining a list of online friends).

当有人登录时,每个客户端是否可以收到此用户登录的通知?同样,如果有人注销,也会生成类似的通知。 (用于维护在线朋友列表)。

IE: is it possible for the server to send some sort of packet to each client, or for the client machine (the guy who logs in/out) to communicate to all other client machines.

IE:服务器是否可以向每个客户端或客户端计算机(登录/注销的人)发送某种数据包以与所有其他客户端计算机进行通信。

Just looking for thoughts on the subject. If you know a good framework for this sort of functionality id like to hear about it. AJAX or JQuery spring to mind, but are these technologies useful for this sort of thing?

只是寻找关于这个主题的想法。如果您知道这种功能的良好框架,就像听到它一样。想到AJAX或者JQuery,但这些技术对这类技术有用吗?

Thanks guys...

3 个解决方案

#1


2  

Yes. Comet is meant for this. Here is a jQuery plugin. And this answer can be useful. Or you can simply ajax-poll the server at a given rate and it will serve changes.

是。彗星就是为了这个。这是一个jQuery插件。这个答案很有用。或者你可以简单地以给定的速率ajax-poll服务器,它将提供更改。

That's from on the client side. The server is simply serving the current state it holds (either in memory, or in a database). However one should give special attention to the case when multiple servers work in a cluster. In that case they should either replicate their memory, or use a "hard" storage (database), so that changes are propagated to all nodes.

这是来自客户端。服务器只是服务于它所拥有的当前状态(在内存中或在数据库中)。但是,当多个服务器在群集中工作时,应特别注意这种情况。在这种情况下,他们应该复制他们的内存,或者使用“硬”存储(数据库),以便将更改传播到所有节点。

#2


2  

Kwwika is library for doing just this sort of thing: http://kwwika.com/

Kwwika是做这类事情的图书馆:http://kwwika.com/

"Want your Web page to update instantly when stuff changes? Just add a KwwikTag. Then the moment you type something into your KwwikScreen (or publish it via the Kwwika API) everyone will see it. No reloading, no polling – the new information appears immediately on the page."

“当你的东西发生变化时,想让你的网页立即更新吗?只需添加一个KwwikTag。然后当你在KwwikScreen中输入内容(或通过Kwwika API发布)时,每个人都会看到它。没有重新加载,没有轮询 - 出现新信息立即在页面上。“

#3


2  

It's possible, but if you think about it, it would be difficult to have it scale well. You could use something like node.js, which is a JavaScript-based http server, very simple (though you could use a normal apache/etc server, just beware of scaling with connections). then you might use flash, web sockets or long polling on the client side to check if anyone has logged in (have a thread-safe queue, database table or flat logfile to hold records of recent log-ins)

这是可能的,但如果你考虑一下,就很难让它很好地扩展。你可以使用类似node.js的东西,这是一个基于JavaScript的http服务器,非常简单(虽然你可以使用普通的apache / etc服务器,但要注意扩展连接)。然后你可以在客户端使用flash,web套接字或长轮询来检查是否有人登录(有一个线程安全的队列,数据库表或平面日志文件来保存最近登录的记录)

Long polling is simply making a request via Ajax to the server, which doesn't respond until something happens (ie, a login) or a timeout occurs.

长轮询只是通过Ajax向服务器发出请求,直到发生某些事情(即登录)或发生超时时才会响应。

#1


2  

Yes. Comet is meant for this. Here is a jQuery plugin. And this answer can be useful. Or you can simply ajax-poll the server at a given rate and it will serve changes.

是。彗星就是为了这个。这是一个jQuery插件。这个答案很有用。或者你可以简单地以给定的速率ajax-poll服务器,它将提供更改。

That's from on the client side. The server is simply serving the current state it holds (either in memory, or in a database). However one should give special attention to the case when multiple servers work in a cluster. In that case they should either replicate their memory, or use a "hard" storage (database), so that changes are propagated to all nodes.

这是来自客户端。服务器只是服务于它所拥有的当前状态(在内存中或在数据库中)。但是,当多个服务器在群集中工作时,应特别注意这种情况。在这种情况下,他们应该复制他们的内存,或者使用“硬”存储(数据库),以便将更改传播到所有节点。

#2


2  

Kwwika is library for doing just this sort of thing: http://kwwika.com/

Kwwika是做这类事情的图书馆:http://kwwika.com/

"Want your Web page to update instantly when stuff changes? Just add a KwwikTag. Then the moment you type something into your KwwikScreen (or publish it via the Kwwika API) everyone will see it. No reloading, no polling – the new information appears immediately on the page."

“当你的东西发生变化时,想让你的网页立即更新吗?只需添加一个KwwikTag。然后当你在KwwikScreen中输入内容(或通过Kwwika API发布)时,每个人都会看到它。没有重新加载,没有轮询 - 出现新信息立即在页面上。“

#3


2  

It's possible, but if you think about it, it would be difficult to have it scale well. You could use something like node.js, which is a JavaScript-based http server, very simple (though you could use a normal apache/etc server, just beware of scaling with connections). then you might use flash, web sockets or long polling on the client side to check if anyone has logged in (have a thread-safe queue, database table or flat logfile to hold records of recent log-ins)

这是可能的,但如果你考虑一下,就很难让它很好地扩展。你可以使用类似node.js的东西,这是一个基于JavaScript的http服务器,非常简单(虽然你可以使用普通的apache / etc服务器,但要注意扩展连接)。然后你可以在客户端使用flash,web套接字或长轮询来检查是否有人登录(有一个线程安全的队列,数据库表或平面日志文件来保存最近登录的记录)

Long polling is simply making a request via Ajax to the server, which doesn't respond until something happens (ie, a login) or a timeout occurs.

长轮询只是通过Ajax向服务器发出请求,直到发生某些事情(即登录)或发生超时时才会响应。