#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171

    Instant div update


    Hi;

    Using JQuery,

    Let's say in a simple chat system, I want to learn how to make a system that if member A starts typing a message in a div (that member B is the receiver), members B sees on his browser window as Member A is typing.....

    I dont think periodic updater would do so, that would drive the server crazy to have it update every milli second. it has to be something else.

    Please share your ideas.

    Thank you.
    Last edited by English Breakfast Tea; February 16th, 2014 at 10:53 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    2 lil clues that might point your right.

    1.) What does Member A have to do to initiate this saying?
    2.) How long do you want it to say this, after a pause in typing, before it no longer reads such?

    That covers Member A. Member B would just need an occasional check to see if such has been set by Member A.
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    67
    Rep Power
    0
    Do you have the rest of the chat system working? If so what technique did you use? Long polling, short polling, net sockets?

    If it long polling, just stop your request if the user types something, and send another request saying they are typing. It doesn't need to be updated on each character.

    Also update the request again if they empty the text field, saying they aren't typing anymore.

    Make sense?
  6. #4
  7. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171
    Originally Posted by someGuyGatsby
    Do you have the rest of the chat system working? If so what technique did you use? Long polling, short polling, net sockets?

    If it long polling, just stop your request if the user types something, and send another request saying they are typing. It doesn't need to be updated on each character.

    Also update the request again if they empty the text field, saying they aren't typing anymore.

    Make sense?
    I made one a few years back with periodic updater. It sucks.
    Last edited by English Breakfast Tea; February 17th, 2014 at 07:49 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    67
    Rep Power
    0
    Originally Posted by English Breakfast Tea
    I made one a few years bavk with periodic updater. It sucks.
    Ok, but, for the problem at hand... how does your chat system work? Does each message refresh the whole page?
  10. #6
  11. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,653
    Rep Power
    171
    Originally Posted by someGuyGatsby
    Ok, but, for the problem at hand... how does your chat system work? Does each message refresh the whole page?
    No I just load a new page in the chat box (just a div) every X seconds.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    67
    Rep Power
    0
    Ok, so you're short polling then by the sounds of it

    If you actually want the typing message to show in "real time", you might need to switch to long polling, but, this may not be an easy task.

    In long polling you keep the connection to the server opening, and when there is data you want, you send it back to the client, close the connection, and then start a new one.

    I've developed a chat system similar to this, but I only use it for personal uses and I've heard in a LAMP stack scalability is an issue.

    I've heard node.js is better for this sort of thing, but I've also heard I can use PHP but maybe look into using nginx instead of apache...

    At any rate, I don't think there is a quick solution for you... but if you want to keep talking about this and look for a solution let me know!

IMN logo majestic logo threadwatch logo seochat tools logo