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

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,959
    Rep Power
    173

    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
    Super Moderator
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,354
    Rep Power
    24
    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 that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, 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,959
    Rep Power
    173
    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,959
    Rep Power
    173
    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