aspose file tools*
The moose likes General Computing and the fly likes how chat works in gmail? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "how chat works in gmail?" Watch "how chat works in gmail?" New topic
Author

how chat works in gmail?

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi Guys,

Does anyone have an idea about how chat works in gmail???

It's a browser based chat program (quite impressive and very responsive). What's the protocol behind this? How it is made? etc.

Thanks.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

It's AJAX and written by Google's framework GWT. Did you have a question about a more specific part of it? I wouldn't know, but we could certainly speculate.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

...written by Google's framework GWT

Really ?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Originally posted by John Todd:

Really ?

I'm not sure if this is sarcasm or a question. In case it is the later:

Google gave a talk about GWT at a JavaSig. They said gmail is written in GWT and then talked about page loading times. Since chat is part of gmail, it stands to reason that this applies.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Jeanne Boyarsky:
It's AJAX and written by Google's framework GWT. Did you have a question about a more specific part of it? I wouldn't know, but we could certainly speculate.



Thanks Jeanne.

Okay, I have some specific questions about it.

Starts with this one, when user type some text in lower text area and press enter key, I guess the "Ajax request" goes to server, and brings the response (probably the same text we typed in lower text area) and that text is updated (appended) in upper text area. Right?
But how does other person get that text instantly, at the same time??? Is my question clear?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

the other person's browser is also sending periodic requests to the server. When you post new text, their next 'check' picks it up and sends it.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by David O'Meara:
the other person's browser is also sending periodic requests to the server. When you post new text, their next 'check' picks it up and sends it.


Thanks David.
I thought the same.
But, when I opened gmail in Firefox (with Firebug). I didn't see that my browser is sending periodic requests in �Firebug�s Net tab�, or for that matter, Firebug does not even show any request going when I press enter key while chatting.

Moreover, I suppose, even if browser sending periodic requests, it will need to send a request each second to achieve that kind of accuracy and responsiveness. Which seems not feasible to me.

David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

why isn't it feasible? keep in mind they have probably spent some time researching responsiveness, and may have found that checking every 3 seconds is enough. If the request and response are typically small unless something is happening (ie rarely) then it becomes 'feasible'
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41461
    
  51
Originally posted by ankur rathi:
But, when I opened gmail in Firefox (with Firebug). I didn't see that my browser is sending periodic requests in �Firebug�s Net tab�, or for that matter, Firebug does not even show any request going when I press enter key while chatting.


I would assume that a JavaScript XMLHttpRequest object is used, which most likely is not captured by Firebug.


Ping & DNS - my free Android networking tools app
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Originally posted by Jeanne Boyarsky:

I'm not sure if this is sarcasm or a question. In case it is the later:

Google gave a talk about GWT at a JavaSig. They said gmail is written in GWT and then talked about page loading times. Since chat is part of gmail, it stands to reason that this applies.

It is a question ofcourse.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

John: Oh good. I wasn't sure .

Ankur: Google's servers are really powerful. They can handle frequent polling requests. And with AJAX, the cost is low. If there isn't an update in your session, it doesn't need to return much data.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Ulf Dittmer:


I would assume that a JavaScript XMLHttpRequest object is used, which most likely is not captured by Firebug.


But when I check my own application, I can see the request generated by XMLHttpRequest object ("ajax request") going in FireBug.

Moreover, in gmail only, I can see other requests which I suppose are generated by XMLHttpRequest object. For example, when we keep mouse cursor on any contact, a small window popup just in right of that, I guess, it�s also an "ajax request" and I can see this request in FireBug.

Naveen Venkat
Greenhorn

Joined: May 23, 2007
Posts: 14
In my opinion the chat in Gmail neither uses AJAX nor GWT. It doesnt use periodic polling and hence periodic requests are not seen in Firebug.

I think it uses a technology called Persistent Http connection. It is a method introduced in Http 1.1 which enables one connection to send/receive mulitple Http requests/responses. It is otherwise called as Keep alive. Hence Chat in gmail is super fast.

Naveen.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Naveen is right. This post and comments describes in more depth.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I am not very sure , but have heard from a friend who claims to have good knowledge in AJAX.

This might be a combination of AJAX (for making requests), HTTP with Keep-Alive and XMPP (in payload of HTTP).
[ June 01, 2007: Message edited by: Rahul Bhattacharjee ]

Rahul Bhattacharjee
LinkedIn - Blog
Naveen Venkat
Greenhorn

Joined: May 23, 2007
Posts: 14
Naveen is right. This post and comments describes in more depth.


Thanks for the link... it is pretty interesting.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thanks Naveen and All.

So it is implemented with "keep alive" http connections. Anyone has an idea about how to implement? GIYF is not working.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Using HTTP header

Connection : Keep-Alive
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41461
    
  51
This is interesting, but the discussion has left me confused.

The article Jeanne linked to seems to describe that the response from the server is never closed - it gets appended to continuously. What gets appended contains JavaScript code that does all kinds of nifty stuff. So far, so good.

But if there is only a single response, there can have been only a single request. That being the case, HTTP Keep-Alive cannot have been used, because that's a feature to make multiple requests over a single HTTP connection.

One possibility I see is that the JavaScript code sent back from the server makes use of XHR to send additional requests, but ignores the response - instead, the response is also sent as part of the original page response, somewhere in the JavaScript code.

Can anyone shed more light on this?
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

A significant difference between HTTP/1.1 and earlier versions of HTTP is that persistent connections are the default behavior of any HTTP connection. That is, unless otherwise indicated, the client SHOULD assume that the server will maintain a persistent connection, even after error responses from the server.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html

I guess all HTTP connections are 'transparently' persistent (or not!)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how chat works in gmail?