Chapter 87. Best Practices for Connecting From Web Browser to Tigase XMPP Server

Table of Contents

Tip #1 - BOSH in Cluster Mode Without Load Balancer
Tip #1 - Encrypted WebSocket Connection
Tip #2 - Encrypted WebSocket Connection - Dealing With Multiple VHosts

Andrzej Wojcik <> v2.0, June 2014: Reformatted for AsciiDoc. :toc: :numbered: :website: :Date: 2013-12-15 19:27

Currently we have 2 ways to connect to Tigase XMPP Server from web browsers:

  1. BOSH (Bidirectional-streams Over Synchronous HTTP)
  2. WebSocket (XMPP over WebSocket)

You will find more informations about these ways for connecting to Tigase XMPP Server with some useful tips below.


BOSH protocol specified in XEP-0124 is one of first protocols defined to allow to establish XMPP connection to XMPP servers from web browsers. Due to that this protocol is widely supported and used by many deployments. It is also easy to use in single server mode. It’s enabled by default in Tigase XMPP Server and available at port 5280.

In clustered mode we can deploy it with load balancer deployed with guarantees that each BOSH connection from web browser will be forwarded to same Tigase XMPP Server instance. So in clustered mode if we have two XMPP server t1 and t2 which are hosting domain we would need to have load balancer which will respond for HTTP request to domain and forward all requests from same IP address to same node of a cluster (i.e. all request from should be forwarded always to node t1.

Tip #1 - BOSH in Cluster Mode Without Load Balancer

There is also a way to use BOSH without load balancer. In this case XMPP client needs to have more logic and knowledge about all available cluster nodes (with names of nodes which will identify particular cluster nodes from internet). Using this knowledge XMPP client should select one random node from list of available nodes and always establish BOSH connections to this particular node. In case if BOSH connection fails due to network connection issues XMPP client should randomly pick other node from list of rest of available nodes.


We have servers and which are nodes of a cluster hosting domain Web client retrieves list of cluster nodes from web server and then when it needs to connect to XMPP server it picks random host from list of retrieved cluster nodes (i.e. and tries to connect using BOSH protocol to host but it should send as name of server to which it tries to connect ( should be value of to attribute of XMPP stream.