Web chat, how to determine user exit?

69 0

I'm trying to do a small app similar to omegle 's random web chat, and there are some things you've added, but it's essentially a web chat. But I'm a web developer.

The problem is how to maintain user login status. That's, when you've logged on to the user, you can exit when you close the page, rather than using a link.

At present, the method has been attempted:

1, using ajax to refresh the message, login. A <event that responds to body> when exiting, sends a post to the server.
Issue: there are different support for browsers, resulting in browsers that aren't responding, or the reason for using jquery. Post may not respond to some asynchronous events in?

2, use long connection to maintain logon status.
Question: whether long connections can feel the user 's disconnect. If you want to develop with a language similar to php, the long connection won't take up system resources?
3, using flash.
Question: this is what I can think of now, but it's a little simple problem.

2 Answers

94 2

1, there's a browser compatibility issue with the watcher event, see: http://w3help. org/zh-cn/causes/SD9026.

2, if a long connection is kept long, even if the client is disconnected, the server doesn't necessarily know that the client is disconnected, so you may need to do some heartbeat, such as each user to keep a heartbeat, update the last heartbeat, and exit this loop when the last time is updated. Reference sources: http://www. Phpfans. Org/? p = 79.

Resource co umption isn't recommended to use node. Js to try: http://cnodejs. org/blog/? p = 1074.
Another chat item: https://github. com/ry/node_chat.

3, flash doesn't work.

...