1

I am looking to create a site that will allow users to create groups and then chat/post within those groups. However, when posts/chats are made within a group, I do not want users to have to reload the page to view these new posts/chats within that group. My question boils down to this: what is your best opinion of how to do this (languages, webservices, etc.)?

I know PHP, SQL, HTML, CSS well and know XML, Javascript, AJAX not so well (I have encountered them enough to read the code and know how they work, but I am by no means skilled or confident with them. I have feeling I will need to read a book on one/all of these to build the kind of site I described.)

Any and all input would be greatly appreciated.

flyingarmadillo
  • 2,041
  • 4
  • 20
  • 37
  • 2
    [Stack Overflow is not your personal research assistant](http://meta.stackexchange.com/a/128553/177538) and [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – Joseph May 20 '12 at 08:28
  • You can try [candy](http://candy-chat.github.com/candy/). But it doesn't have create groups. You can configure this with xmpp chat servers like ejabberd or Openfire. – Pradeep Sanjaya May 20 '12 at 08:42
  • 1
    Also I suggest long polling If you develop a web chat client using php/ajax – Pradeep Sanjaya May 20 '12 at 08:43
  • flying - To clarify, long polling isn't the same as polling. Long polling is also known as reverse AJAX, or Comet, just to clarify Pradeep's excellent suggestion. – jmort253 May 20 '12 at 08:44

2 Answers2

3

The Web does a great job handling the typical request/response model where a client makes a request and a server responds with a resource. However, when it comes to applications where the server must send data to the client without that client requesting the data, this is where we must get creative.

There are a few different methods that one can use to facilitate a real time Web-based application.

Polling:

Polling involves the client periodically making requests to the server in order to receive updates. There are two main problems with this approach: First, there may not be any data for the server to push for a very long time. Hence, lots of bandwidth is potentially wasted continuing to poll the server for updates. Second, the polling rate determines how real-time the application feels. While a fast polling rate will make the updates appear sooner, it wastes bandwidth. Conversely, polling in longer intervals uses less bandwidth, but the downside is that updates don't appear as quickly.

In general, this is a very poor solution to use for a chat application in the year 2012.

Comet/Reverse AJAX:

Comet is a technique that has been successfully used in the last 5 years to take the concept of request/response and use a hack to simulate a real-time effect. The general idea behind Comet is that the client makes a request to the server, and the server holds the connection open indefinitely. The server waits until there is an update to send to the clients. Once the update is ready, the server sends the response, which simulates the server making the request to the client. Once the client receives the response, it opens a new connection, and the process repeats.

This technique has been shown to scale to over 20,000 simultaneous connections on some platforms when combined with Continuations, which ensure waiting threads are freed up for other tasks.

This not only saves bandwidth, but it makes the application feel extremely real time.

Websockets:

Websockets was introduced in HTML5 as a replacement for Comet, using the ws:// protocol instead of http. However, this has not yet been widely adopted by all browser vendors, and there may still be discussions regarding the specification for the protocol. It has many of the same benefits as Comet.


For more information on Comet, check out Comet and PHP and the challenges of Comet in PHP. For client side integration, check out the Dojo Cometd Library.

Community
  • 1
  • 1
jmort253
  • 32,054
  • 10
  • 92
  • 114
  • `However, when posts/chats are made within a group, I do not want users to have to reload the page to view these new posts/chats within that group. My question boils down to this: what is your best opinion of how to do this (languages, webservices, etc.)?`. Comet or Websockets is the answer. That's what this entire answer was about, as well as why one shouldn't use polling solutions. – jmort253 May 20 '12 at 09:02
-1

I would have said AJAX is the best method of doing this. Alternatively, create an iframe which reloads

Ben
  • 663
  • 6
  • 25
  • Both of those solutions essentially involve polling, which are not really the best, most efficient, nor most modern methods of solving this problem. – jmort253 May 20 '12 at 08:51
  • He doesnt ask for that. He asks for a solution as to how it can be done. Please remove your downvote to a valid answer – Ben May 20 '12 at 08:59
  • You didn't mention a valid solution. If you use AJAX for this, you're going to need to poll continuously, which isn't a good solution. (Also, you shouldn't make assumptions as to who downvoted you. It wasn't me. I'm out of votes for the day.) – jmort253 May 20 '12 at 09:04