How to send a query to the browser from time to time?

A

Admin

I am creating a chat application like Messenger for the web (using the
browser) and I'm wondering if there is a way to receive new messages from
time to time from the server other than refreshing the page each 5 sec.

If there were a way to have the server-side application send new messages
to the browser this would be awesome because it would save dramatically on
bandwidth. The application would consume bandwidth only when there are new
messages. There would be no communication client-server until people write
a new message.

Do you know if it's possible?
 
S

Simon Dahlbacka

Short answer: Not using HTTP.

However, you can use something like AJAX to just load new data from
time to time and not the entire page.

Or you might be able to keep the connection alive and occationally send
stuff to the client using chunked transfer.

I'd go for the ajax route if you don't need to support old browsers.
 
P

phr

Admin said:
If there were a way to have the server-side application send new
messages to the browser this would be awesome because it would save
dramatically on bandwidth. The application would consume bandwidth
only when there are new messages. There would be no communication
client-server until people write a new message.

Do you know if it's possible?

Some people have done stuff like that with multipart mime encodings
and chunked transfers. I've looked into it but I'm not sure of the
exact mechanism any more. It's kind of messy.

The other usual way is to open a tcp connection from a java applet.
I don't like that since it means you need java in your browser.

There's a chat app called arsc that you might look at:

http://manuel.kiessling.net/projects/software/arsc/

Warning, last time I looked at it, it had some security bugs.
 
A

Admin

I'd go for the ajax route if you don't need to support old browsers.

I already use AJAX on several applications, but I don't want to use it in
this one because it would poll the server a lot and it may bring the
server down if there are many people using the chat application at the
same time (too many queries to the database).
 
S

sp1d3rx

rewrite the server to bake a /lastmsg/ folder with the last message in
it. otherwise, my only suggestion is to use another protocol instead of
http.
 
L

Leif K-Brooks

Admin said:
I am creating a chat application like Messenger for the web (using the
browser) and I'm wondering if there is a way to receive new messages
from time to time from the server other than refreshing the page each 5
sec.

Here's a pretty basic example I wrote a while ago using Twisted:
<http://tw.ecritters.biz/files/twistedchat.py>. The server keeps the
connection open and sends messages when they occur, with the side effect
of keeping the browser's page-loading indicator alive indefinitely.
 
M

Mike Meyer

Simon Dahlbacka said:
Short answer: Not using HTTP.

However, you can use something like AJAX to just load new data from
time to time and not the entire page.

AJAX is overkill for this. If you just want to automatically refresh
the page automatically, you can use a meta refresh tag.

<mike
 
A

Admin

AJAX is overkill for this. If you just want to automatically refresh
the page automatically, you can use a meta refresh tag.

Reloading the page automatically would be even worse because it would
spend a lot of bandwidth, it would reload all the page and graphics all
the time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top