通知多个 Java 小程序/应用程序服务器上的更改的最佳方法
我需要知道最好(最快)的方法来让服务器(最好是基于 php 的服务器,但也可以使用 google 应用程序引擎设置 jsp/servlet)通知几个 java 小程序/应用程序发生了更改数据。
我想象的工作方式与我认为在线 java 游戏(如 Runescape)的工作方式非常相似
用户 1:更改服务器上的数据。
服务器:向用户 1 返回成功,通知连接的计算机发生变化。
连接的计算机 1:处理更改,将成功返回到服务器。
连接的计算机 2:处理更改,将成功返回到服务器。
连接的计算机 3:处理更改,将成功返回到服务器。
连接的计算机 4:处理更改,将成功返回到服务器。
我希望整个过程能在半秒内完成,并且不涉及轮询,因为会有很长一段时间什么都没有,然后突然有 4 个事件连续发生。
I need to know the best (fastest) way to have a server (preferably a php based one, but a jsp/servlet one could be set up as well using google app engine) notify several java applets/applications that a change has occurred to the data.
The way i am picturing this to work will be very similar to that of the way i think an online java game (like Runescape) works
User 1: Changes data on server.
Server: returns success to User 1, notifies connected computers of change.
Connected Computer 1: processes change, returns success to server.
Connected Computer 2: processes change, returns success to server.
Connected Computer 3: processes change, returns success to server.
Connected Computer 4: processes change, returns success to server.
I am hoping to have this entire process complete in half a second, and not involve polling as there will be long durations of nothing, followed by a sudden moment where 4 events happen in succession.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它必须非常快速和可靠,我根本不会使用网络服务器。我有一个独立的服务器进程,并让客户端与其建立直接的 TCP 连接。更多的应用程序使用来自网络服务器的推送,但我仍然发现它非常不可靠。每个客户端都需要一个阻塞套接字读取的线程。当数据到达客户端系统时,他们将立即获取数据。
If it has to be very fast and reliable, I wouldn't use a web server at all. I'd have a stand-alone server process and have the clients make direct TCP connections to it. More application are using a push from a web server, but I still find it very unreliable. Each client would need a thread that blocks on a socket read. They will get the data immediately when it arrives on the client system.
查看 ICEPush 的 Java 实现。我找到了 2 篇帖子,演示了如何在 PHP 中实现类似的功能。这两篇文章都展示了 AJAX 客户端,但是您可以将其逆向工程为 Java 小程序中的简单 HTTP 请求。本质上,所有这些引擎所做的就是让客户端与服务器保持一个挂起的 HTTP 请求,当服务器有客户端的信息时,该请求就会返回。基本上,客户端向服务器发出请求,如果服务器在队列中没有该客户端的事件,它只会保留该请求并休眠,直到有通知添加到队列或达到超时服务器返回请求并且客户端解析它,此时它立即向服务器发出另一个请求,并且该过程重新开始。 ICEPush 示例的超时时间略低于 60 秒。
http://www.zeitoun.net/articles/comet_and_php/start
http://www.webreference.com/programming/javascript/rg28/index.html
Check out ICEPush for a Java implementation. I was able to find 2 posts that demonstrate how to implement similar in PHP. Both posts show an AJAX client, however you can reverse engineer it into simple HTTP requests in a java applet. Essentially all these engines are doing is having the client maintain a hanging HTTP request with the server, which is returned when the server has information for the clients. Basically, the client makes a request to the server and if the server doesn't have an event in the queue for that client it just holds on to the request and sleeps until there is a notification added to the queue or a timeout is reached at which point the server returns the request and the client parses it at which point it immediately makes another request to the server and the process starts over again. The timeout for ICEPush examples is just under 60s.
http://www.zeitoun.net/articles/comet_and_php/start
http://www.webreference.com/programming/javascript/rg28/index.html