I decide to make a chat room. (Server side is PHP or Java). First thing, I use AJAX base on this idea:
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.
the disadvantage of this ways is it not efficient. It’s not very problem in chat program, but I decide to make some other function such as draw on screen and share between people.
So, I decide to use other ways. Here is new way :
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.
I base on Observer Pattern of Gof. And this way works better than other. But the problem I have met in this new way is :
1) what “information” about user will be save. (IP address, … ?)
2) how to send to user ? (when users don’t have request to server).
Please tell me the solution, please. And better, if it’s more detail in Java or PHP.
You may use Session to identify and store information about the connected users. The main work is done by the server, and many web framework (PHP, Java, or other) can handle this for you.