Ajax和jQuery聊天

I'm building a PHP chat (similar to the one on badoo.com).\ Here is the thing to check for messages and who is typing. I send a request per second, it got a little slow. So, I started searching around and trying to figure out how Facebook pulls out a huge amount of that, without sending so many AJAX requests. I noted they just send one and it keeps looping, until some changes occur (e.g. a friend gets online, a new message posted...) and then they send another one and so on.

My question is: How can I do that?

Maybe you could take a look at HTML5 Websockets.

Here is a good presentation about it. Long-polling is included in the presentation:

Presentation