3

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?

3
  • If I use continuous polling, it uses up masses of bandwidth. If I leave the connection open it uses up connections and causes problems. They're both maybe doable, but Gmail seems to be doing neither and I'd rather avoid them if I could. Commented Oct 17, 2010 at 22:30
  • 2
    GMail is absolutely using a keep-alive connection; sometimes called a "hanging GET". See the connection to b.mail.google.com/mail/channel/bind?VER=8&at=etc... Commented Oct 17, 2010 at 22:32
  • another option is to write a small java applet that will do the communication for you, or write the whole chat client in java. Commented Oct 17, 2010 at 23:03

6 Answers 6

2

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)?

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

Comet perhaps? http://en.wikipedia.org/wiki/Comet_(programming))

1 Comment

Comet starts and ends with HTTP.
0

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.

Comments

0

They use Comet. Further reading -> http://www.ekhoury.com/blog/2007/02/07/ajax-alternatives-gmail-choice/

Comments

0

You might consider WebSockets.

Advantages:

  • Much less overhead than HTTP (or AJAX/Comet)
  • Easy to implement on the client side.
  • Closely related to HTML5, so using it gets you "bonus points". :-)

Disadvantages:

  • Requires a browser with WebSockets support or Adobe Flash support: web-socket-js project provides a fallback Flash emulator.
  • You need something on the server side that supports WebSockets.

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.