Reputation: 33
I'm trying to write a chat client using javascript, but I'm being hindered by only being able to communicate with the server using XMLHttpRequest which as far as I can tell is completely unsuitable, as many have told me.
I've looked for other networking functions but haven't found any and been told that there aren't any. It's almost enough to make me stop looking, except Gmail seems to be doing it somehow. It makes no requests for several minutes, then as soon as I send an email to myself, my inbox in another window sends a POST request and receives the email. Since it hasn't sent any http requests to the server for minutes (I checked using firebug) it can't have been talking to the server that way, so how does it know when it has an email to receive?
Upvotes: 3
Views: 482
Reputation: 11563
I asked a similar question a while back, take a look at it there are pretty nice answers.
How can I start ajax push website (activemq or cometd or something else)?
Upvotes: 2
Reputation: 73197
You might consider WebSockets.
Advantages:
Disadvantages:
For the back-end check out pusherapp which handles the back-end of the type of application you are wanting to create. You get 5 simultaneously clients and 10,000 messages per day for free.
Here is a google intro to WebSockets: http://blog.chromium.org/2009/12/web-sockets-now-available-in-google.html
Also, check out wsproxy which is a WebSockets to generic TCP sockets proxy included with noVNC (HTML5 VNC client). noVNC has a C and python version of wsproxy. Disclaimer: I created noVNC.
Upvotes: 0
Reputation: 23281
They use Comet. Further reading -> http://www.ekhoury.com/blog/2007/02/07/ajax-alternatives-gmail-choice/
Upvotes: 0
Reputation: 61793
GMAIL does use HTTP. The only difference is that they don't do polling, but I believe tags http-streaming. It keeps the connection open instead of closing it and trying again.
You did not specifiy what kind of server architecture you are using, but You could also use BOSH(for example prosody does have BOSH) to achieve this. Strophe.js is a real clean javascript library to achieve this.
Upvotes: 0
Reputation: 7238
Gmail uses a variant of Comet approaches. I'm not sure of the specifics, but I believe it is some sort of long-poll running in <script>
tags or an <iframe>
. The Wikipedia article on Comet has more detail.
Upvotes: 1