XMPP with BOSH: using HTTP as a transport protocol
Translation of the original in Catalan. Read it in: CatalàCastellano
Part 2 of 6XMPP
- XMPP: introduction
- XMPP with BOSH: using HTTP as a transport protocol
- Telepathy Glossary
- Articles about XMPP
- VNC session with TCP proxy over XMPP
- XMPP tools
The power of working with
(Bidirectional-streams Over Synchronous HTTP) lies in the fact that, although apparently the only way to implement XMPP over HTTP would be through polling techniques, that is, the client periodically connecting to the server to ask whether there is any new information for it.
Well, BOSH manages to improve this algorithm and what it tries to describe is something like this:
- The client makes an 'HTTP request' connection to the server
- The server sends no response, so the connection is not closed.
- When the server has some (asynchronous) information to send to the client, it then looks for an open connection from the client that is waiting for a response, that is, one that is at point 2. Then what it does is send the information through that connection as a 'request response'. The connection is closed.
- As soon as the client receives the information, immediately after the link is closed, it opens a connection to the server again, that is, we go back to point 1.
Obviously when the client has something to send, that is done at point 1.
In practice, what Jabber/XMPP servers have to offer access via BOSH is a sort of proxy that receives the HTTP connections and processes them as I explained above; on the other side it captures the events it receives from each of the XMPP clients it is instantiating and links the data streams it receives through XMPP to the HTTP sockets that are waiting for information.
BOSH servers embedded in XMPP servers
Obviously this leads us to think that we can use a BOSH server for an XMPP server that does not support it, acting as a proxy. This could be programmed fairly easily with twisted; on the other hand, there are XMPP servers that already support the BOSH server out of the box, some examples are:
,
,
and
.
Advantages of having the BOSH server inside the XMPP server:
- It is often better tested than the code we can write ourselves or that a third party has developed to do this task.
- A priori it should be more efficient, since the part that receives events/signals is done through the native API and not through an XMPP client. This saves resources and makes it more efficient at its task.
- It is easier to configure, often you only have to uncomment the corresponding line of the configuration file and that's it.
Since not everything could be advantages, here come the disadvantages:
- A BOSH server that is embedded in an XMPP server obviously can only serve the requests that go to that server, therefore, if we want this to be scalable we will have to set up a load balancer on the HTTP port to keep redirecting connections between different BOSH servers.
- Support for the BOSH server is tied to the support the community gives to the XMPP server it is tied to, and that is not always enough.
When we do not have to support more than one XMPP server, and that one already supports BOSH, there will never be problems. Things will get complicated when we have to scale that infrastructure.
Dedicated BOSH servers, therefore independent from the XMPP server
For example:
,
,
and
. As for the advantages and disadvantages of this type of BOSH server, they are obviously the same as the previous ones but the other way round.
A dedicated BOSH server will therefore be able to connect to an XMPP network through a federated XMPP server without problems. The overhead cost this entails is often more than justified. Bear in mind that for each client you will often need two TCP/HTTP connections plus one TCP/XMPP connection; therefore, three open sockets for each client connected to the BOSH server. With this I suppose it is clear how similar this is to a proxy server, isn't it?
As I pointed out before, scaling BOSH servers through 'load-balancers' is very simple; for example I recommend
. Think that with this 'load-balancer' we can have up to 10,000 HTTP connections while consuming only 2.5Mb of RAM. Therefore, this is also a very good reason to use BOSH servers externally. In fact, this is not only my opinion, they think so here too:
.
In fact, there are people bold enough to dare say that XMPP is better if clients use BOSH to access it; in fact, if you read the reasoning it doesn't sound that bad:
.
Final note
In case anyone still had not got it clear, this is what the XMPP libraries implemented in JavaScript use, that is, the chat clients (Jabber/XMPP) that work over the Web. For example, the client we can use from the gmail web page.
Obviously Jabber/XMPP applications are endless and not only as chat clients. Therefore, you can take advantage of these JS libraries that implement BOSH to show interactively in your web interfaces any kind of content you get through the XMPP network.
1 comment
Comments from the old blog, as they were written. Comments are closed.
pau
Les actuals implementacions de "xats" de Google i Facebook sobre http implemenen el que comentes, asincronous comunications against polling !