+ Reply to Thread
Results 1 to 5 of 5

Thread: Help needed to built a chat feature.

  1. #1
    napster7 is offline x10Hosting Member napster7 is an unknown quantity at this point
    Join Date
    Dec 2009
    Location
    India
    Posts
    6

    Help needed to built a chat feature.

    I want to built a feature on my website for a project where a user can see a new post sent to him without refreshing the page.

    What i am doing now is that i call a function every second to see whether a new post has arrived or not? But this is not a good programming practice.

    Hence my question is that, how do i make it possible for the server to say to the client that a post has been arrived for you. Then only the client should call the function to fetch the post and not every second.

    I found some topics here, but were not useful.

    Please help me.

    Thank You.
    Last edited by napster7; 04-14-2010 at 09:27 AM. Reason: To make my question more clear

  2. #2
    DeadBattery's Avatar
    DeadBattery is offline Community Support Team DeadBattery is a name known to allDeadBattery is a name known to all
    Join Date
    Mar 2008
    Location
    localhost
    Posts
    4,019

    Re: Help needed to built a chat feature.

    I don't mean to interrupt here but just to let you know, chats aren't allowed on x10Hosting servers.


  3. #3
    napster7 is offline x10Hosting Member napster7 is an unknown quantity at this point
    Join Date
    Dec 2009
    Location
    India
    Posts
    6

    Re: Help needed to built a chat feature.

    Sorry.. but i didn't mean to use chat on x10 servers.

    Actually it is a part of my college project, hence i thought i could get some help over here.

  4. #4
    lostcommander's Avatar
    lostcommander is offline x10Hosting Member lostcommander is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    United States of America
    Posts
    52

    Re: Help needed to built a chat feature.

    This rather depends, napster7, on whether you mean to alert people as to when they have received a PM (ala Facebook's notifications) or whether you mean something like AJAX Chat (disallowed on x10) or a shout box (disallowed on x10).

    In any of those cases, though, to the best of my knowledge you will have to refresh at least part of the page since HTTP servers NEVER initiate contact with a client over the internet. One way around this is to write some JavaScript that appends a JavaScript file written in PHP (which includes the database calls to find out whether there are any new messages or not yet, and the JS to change display values as needed) to the current page. The client will then make that request at some standard interval. The difference then is then only the interval length and how interactive you want it to be: e.g. Gmail rechecks like every 2-5 minutes, Facebook seems to check every 1-3 minutes, and JS+PHP+MySQL -powered web chat probably checks every few seconds (making a TON of page and database calls in the process, which is why they are not allowed around here).

  5. #5
    essellar's Avatar
    essellar is online now Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,152

    Re: Help needed to built a chat feature.

    Chat apps will always be "chatty", and over HTTP(s) they will always have to be client-pull, but they don't need to be particularly expensive in terms of data traffic or database calls. Ajax requests, for instance, can be HEAD requests until a new message is found, message data can be persisted in memory rather than going through the database, etc. I'm building something similar but a bit more ambitious on Google AppEngine right now, and the bandwidth and resource usage is really pretty small, thanks in large part to the memcache feature and HEAD requests. Think hard about what actually has to travel over the pipes, and what the check interval really needs to be to seem responsive -- I was able to build a live, near-real-time charity auction site on a single-processor 800MHz PIII Lotus Domino server (with a full 256MiB of RAM) that supported 1500 concurrent users and 40 simultaneous items up for bid back in 2001, and I had to use iframes/ilayers to do it since XmlHTTPRequest was an IE-only thing (and you couldn't count on MSXML being installed).

    Chat can be done in a lightweight, efficient manner. But then, so can most webby things -- I consider it a failure if any web page I create causes more than five requests on load or "weighs" more than 20K all in (including cachables), but I've seen a lot of static, do-nothing pages that load Dojo, a 50K CSS file and a thousand tiny images for no reason, simply because the developer didn't think. Don't become one of those.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

+ Reply to Thread

Similar Threads

  1. Profile pic feature for my login script - NO CODES NEEDED
    By begamer26 in forum Programming Help
    Replies: 8
    Last Post: 04-03-2010, 06:21 PM
  2. Website built on Drupal 6.1 / Web Hosting ..
    By Jadmin in forum Free Hosting
    Replies: 1
    Last Post: 11-04-2009, 03:00 AM
  3. My Website...Online Game built With PHP
    By exemption in forum Review My Site
    Replies: 14
    Last Post: 10-01-2008, 11:33 PM
  4. Custom Built pcs or Bought Pc?
    By disturbedart in forum Crossfire
    Replies: 33
    Last Post: 10-20-2006, 02:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers