By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

AJAX chatroom, how to???

P: n/a
Hi, friends,

I am hoping to write a chatroom with the AJAX methodology. I knew I
can set periodic refreshment from the client-side code and make the
input from any visitor get updated to all others. But I think this
method is very low efficient since I have to contact the server in a
very short time interval.. Is there any more practical ways to do this
with AJAX?

Many thanks for your suggestions and time..

Regards,
lihao(XC)
Feb 4 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
VK
On Feb 4, 10:54 pm, "lihao0...@gmail.com" <lihao0...@gmail.comwrote:
Hi, friends,

I am hoping to write a chatroom with the AJAX methodology. I knew I
can set periodic refreshment from the client-side code and make the
input from any visitor get updated to all others. But I think this
method is very low efficient since I have to contact the server in a
very short time interval.. Is there any more practical ways to do this
with AJAX?
XHR support HEAD, GET and POST request.

Shall your XHR use GET or POST to submit user input to the server and
to update the client-side chat as well.

Shall it send HEAD request every 1sec on setTimeout while idle (no
user submission) with properly set If-Modified-Since and other
relevant HTTP headers.

Shall the server-side script threats properly HEAD request and returns
proper meta data (yes no data / no new data)

Shall your client-side script reads properly meta data received and
either wait for another second or issues GET/POST request immediately.

Another option is to use Comet-like hacks, but I hate this too much to
discuss, so just giving you an info resource:
http://en.wikipedia.org/wiki/Comet_(programming)

Feb 4 '08 #2

P: n/a
VK <sc**********@yahoo.comwrites:
Another option is to use Comet-like hacks, but I hate this too much to
discuss, so just giving you an info resource:
http://en.wikipedia.org/wiki/Comet_(programming)
Now you've gone and made me curious.

:-)

Joost.
Feb 4 '08 #3

P: n/a
Joost Diepenmaat wrote:
VK <sc**********@yahoo.comwrites:
>Another option is to use Comet-like hacks, but I hate this too much to
discuss, so just giving you an info resource:
http://en.wikipedia.org/wiki/Comet_(programming)

Now you've gone and made me curious.
Comet technology, which is not a hack (in the bad sense) at all, has been
discussed here recently.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Feb 4 '08 #4

P: n/a
Thomas 'PointedEars' Lahn <Po*********@web.dewrites:
Joost Diepenmaat wrote:
>VK <sc**********@yahoo.comwrites:
>>Another option is to use Comet-like hacks, but I hate this too much to
discuss, so just giving you an info resource:
http://en.wikipedia.org/wiki/Comet_(programming)

Now you've gone and made me curious.

Comet technology, which is not a hack (in the bad sense) at all, has been
discussed here recently.
/browses...

No-one's recently brought up any real-world problems with it, then?

Joost.


Feb 4 '08 #5

P: n/a
Hi, guys:

Thanks all for your helpful responses. I've read the book
"Professional AJAX edition-2" this afternoon, and think the Comet and
HTTP streaming is what I need to try. :-)

On Feb 4, 3:38*pm, VK <schools_r...@yahoo.comwrote:
On Feb 4, 10:54 pm, "lihao0...@gmail.com" <lihao0...@gmail.comwrote:
Hi, friends,
I am hoping to write a chatroom with the AJAX methodology. I knew I
can set periodic refreshment from the client-side code and make the
input from any visitor get updated to all others. But I think this
method is very low efficient since I have to contact the server in a
very short time interval.. Is there any more practical ways to do this
with AJAX?

XHR support HEAD, GET and POST request.
Shall your XHR use GET or POST to submit user input to the server and
to update the client-side chat as well.
I have no expreience with HEAD on an AJAX call, not sure if that
helps. but basically I think I will use a 'POST'.
Shall it send HEAD request every 1sec on setTimeout while idle (no
user submission) with properly set If-Modified-Since and other
relevant HTTP headers.
I thought of using setTimeout to do this, but as you mentioned it's
waste of resources when the activities are low or when users are
idle. :-( All no-cache HTTP headers, including Cache-Control, Pragma,
Last-Modified, Expires, have been taken care from my server-side code)

Shall the server-side script threats properly HEAD request and returns
proper meta data (yes no data / no new data)
Shall your client-side script reads properly meta data received and
either wait for another second or issues GET/POST request immediately.
I just need a model to update client-side content only when change
from other sides is made. and I think Comet(HTTP streaming)'s push
architecture is what I was looking for..
Another option is to use Comet-like hacks, but I hate this too much to
discuss, so just giving you an info resource:http://en.wikipedia.org/wiki/Comet_(programming)
really appreciate your helpful suggestions and the link: -)

Best,
lihao(XC)


Feb 4 '08 #6

P: n/a
VK
On Feb 5, 1:36 am, Joost Diepenmaat <jo...@zeekat.nlwrote:
Thomas 'PointedEars' Lahn <PointedE...@web.dewrites:
Joost Diepenmaat wrote:
VK <schools_r...@yahoo.comwrites:
Another option is to useComet-like hacks, but I hate this too much to
discuss, so just giving you an info resource:
http://en.wikipedia.org/wiki/Comet_(programming)
Now you've gone and made me curious.
Comettechnology, which is not a hack (in the bad sense) at all, has been
discussed here recently.

/browses...

No-one's recently brought up any real-world problems with it, then?
Comet is _terrible_ problem of the Web. It is more terrible because
99.9% of users (including the original technology promoters) having no
clue what are they doing with the way the WWW works.

RFC 2068
8.1.4 Practical Considerations
Clients that use persistent connections SHOULD limit the number of
simultaneous connections that they maintain to a given server. A
single-user client SHOULD maintain AT MOST 2 connections with any
server or proxy. A proxy SHOULD use up to 2*N connections to another
server or proxy, where N is the number of simultaneously active
users. These guidelines are intended to improve HTTP response times
and avoid congestion of the Internet or other networks.

Of course SHOULD is not MUST, but all major players do obey core RFCs

http://developer.mozilla.org/en/docs...st_Connections
http://support.microsoft.com/kb/282402

As the result we are having many HTTP channels cluttered in unexpected
way and - of course - "weird" client-side problems like the one I'm
answering right now at
http://groups.google.com/group/mozil...d00e400f23cdfe

Yes, I know exactly where his problem is so it would be enough to post
the mozilla.org link. But he is doing two things at once where each
one more and more terrible and dishonest: 1) he is doing Web-chat and
that one I would just smile over but tolerate and 2) he is doing Web-
chat with Comet. For that he must be punished by sueding out the
solution. Comet makes me feel like to be an a**hole.
Feb 9 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.