in reply to OT? Best method for real time chat application

HTTP Keepalive is a resource to get more than one file in the same HTTP connection. Since you are not sending files, you are sending dynamic data, you can't use this resource, since Apache will close the connection after a cgi/mod_perl call, and since your dynamic data doesn't have a defined size, specially for a chat, where you don't know the full size of the data.

I think that what you want to say with HTTP Keepalive (let me know if I'm wrong), is to keep the port oppened sending data to the users for a few minutes. So, each user will create, let's say, a CGI call, and the cgi will work for some minutes sending data, than it closes to not create errors in the browser, and refresh making a new CGI call.

The point is not the real time question, is the number of users that will connect in your server. If you will have 100 users connected with "HTTP Keepalive" (as you say), you will have 100 process of Apache and 100 conections at the same time to the server, what will make your server very slow!

Here I use the 1st option for a chat of 300 peoples based in a mod_perl script (to avoid startup time) and it works very well and is similar to real time. What I do is to have a hidden frame that refresh each 10s and receives the new msgs, and write with javascript the new msgs in the main frame where the user sees the msgs, and don't know or see any page refresh.

To create a streaming chat (your "HTTP Keepalive" option), you can't make it based in a Apache server, or any WEb server, you need to implement your own HTTP server and let it lead with all the users at the same time, in one process. We can see that in the big ISP, that uses a script in some 8080 port, and accept multiple connections to this port, and handles all the users with one process. The problem is that you need to habe full access to the server to can run something like that. Also you will use more bandwidth, since keep a TCP connection alive uses bandwidth, even if no data is sent.

The 3d option is to create an Applet that make the connection to the server and get the msgs and write them with javascript in the main page, or shows everything inside the applet. But use a applet will be useful only if the connection to the chat server is not over HTTP, since make a HTTP call will always send much more headers than chat messages, and you will not make something that can't be done with javascript, and you will not make something better. If you can make a applet make it to connect to some port each 5s where it get and send msgs, and make this over your own protocol, something like a simple IRC protocol will work

Graciliano M. P.
"Creativity is the expression of the liberty".

  • Comment on Re: OT? Best method for real time chat application