Jump to content

Is Client Still There?


imperium2335

Recommended Posts

Hi,

 

I am building a simple AJAX chat system, but I have thought of an issue.

 

What if a user pulls the plug on the connection for whatever reason (powercut etc), how will my system know to remove their "active users" entry in my DB and thus show them as no longer in the chat?

 

Is there a way to check for a client of a given IP address taking part in an AJAX request? So I could have something where if no AJAX request was made in 10 seconds, they must have disconnected?

 

Any help or advice is much appreciated!

Link to comment
Share on other sites

Just ask them

 

All jokes aside! Yes, you would poll your server every n seconds to fetch the new contents and update their status, anyone where the delta between last update time and the current time exceeds the idle time is considered offline. Preferably you should return this to any active clients so they can update their list of users in the chat.

Link to comment
Share on other sites

Thanks for the reply!

 

Yes I already have something that deletes a user if no activity after 30 minutes, but I want to know if there is a way to detect if they have hard disconnected. I thought about pinging the clients IP address using phps exec() function but I hear not everyone on the net is pingable. What do you think?

Link to comment
Share on other sites

Pinging won't solve anything. Pinging only means that the host is reachable not that they are still chatting. So no, there is no real way except maybe using the onunload event of which I'm unsure if it triggers correctly on all browsers/platforms.

 

What you actually need is a socket which is available as of HTML5: WebSockets, you can find a tutorial of how to use it on NetTuts+

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.