有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java服务器如何自动向用户发送数据

我决定建一个聊天室。(服务器端是PHP或Java)。首先,我基于这个想法使用AJAX:

1) both users will often send request to server to take the latest message.

2) when one user types message and enter, the text will be send to server, and server save it to database and waiting for other users take it.

这种方法的缺点是效率不高。这在聊天程序中不是什么大问题,但我决定做一些其他的功能,比如在屏幕上画画和人与人之间的分享

所以,我决定用其他方法。以下是新方法:

1) when users connect to chat room, there are "some ways" to remain them.

2) when some one send text to server, the server will "automatically" send this text to the rest of users.

我基于Gof的Observer Pattern。这种方法比其他方法更有效。但我以这种新方式遇到的问题是:

1) what "information" about user will be save. (IP address, ... ?)

2) how to send to user ? (when users don't have request to server).

请告诉我解决办法。如果在Java或PHP中更详细,则更好


共 (1) 个答案

  1. # 1 楼答案

    您可以使用会话来识别和存储有关连接用户的信息。主要工作由服务器完成,许多web框架(PHP、Java或其他)都可以为您处理