

HAProxy switches automatically from HTTP to tunnel mode when the client request a websocket. In this configuration, the websocket and the web server are on the same application. High-availability and routing is managed by HAProxy. So basically, I’ll have 2 servers, each one hosting web pages on Apache and an echo application on websocket application hosted by nodejs.
EJABBERD WEBSOCKETS INSTALL
Here is the procedure to install node.js and the websocket module on Debian Squeeze.Įxample code is issued from, at the bottom of the page. It owns a websocket module we’ll use in the test below. Node.js is a platform which can host applications. Timeout connect is not used since the TCP connection is already established 🙂 Testing websocket with node.js

If everything goes well, the websocket is established, then HAProxy fails over to tunnel mode, no data is analyzed anymore (and anyway, websocket does not speak HTTP).
EJABBERD WEBSOCKETS UPGRADE
It detects automatically the Connection: Upgrade exchange and is ready to switch to tunnel mode if the upgrade negotiation succeeds. The diagram below shows how things happens and HAProxy timeouts involved in each phase:ĭuring the setup phase, HAProxy can work in HTTP mode, processing layer 7 information. It can even route regular HTTP traffic from websocket traffic to different backends and perform websocket aware health check (setup phase only).


When a server with websocket capability receive the request above, it would answer a response like below: HTTP/1.1 101 Switching Protocols The most important part is the “ Connection: Upgrade” header which let the client know to the server it wants to change to an other protocol, whose name is provided by “ Upgrade: websocket” header. Sec-WebSocket-Key: avkFOZvLE0gZTtEyrZPolA= How does a websocket work?īasically, a websocket start with a HTTP request like the one below: GET / HTTP/1.1 Furthermore, websockets re-use the HTTP connection it was initialized on, which means it uses the standard TCP port. So a new protocol has been designed: websockets, which allows a 2 ways communication (full duplex) between a client and a server, over a single TCP connection. the client send a request to the server and the server answers as soon as he has an information to provide to the client (also known as long time polling)īut those methods have many drawbacks due to HTTP limitation.the client request the server at a regular interval to check if there is a new information available.
EJABBERD WEBSOCKETS UPDATE
Some websites or web applications require the server to update client from time to time. Furthermore, a server can answer only one time to a client request. In any case, a server can contact a client. HTTP protocol is connection-less and only the client can request information from a server. Learn more by registering for our webinar: “ Introduction to HAProxy Stick Tables“ Why Websocket?
