

The MQTT Broker places the MQTT data in the WebSocket framework and sends it to the web client. The interesting thing is, you don’t need to refresh your client side ( your web browser) or get polling for viewing your data. Now, these two powerful protocols (MQTT and WebSockets) comes together to make some tremendous possibilities on data transmission (or even control). I have used Mosquitto Broker in this tutorial, you can use any broker of your own, for example, a cloud based MQTT like HiveMQ. In this tutorial, we will learn how to enable MQTT over WebSocket on your windows machine. So, 2-way client server communication is possible with WebSockets.

Because, the HTTP protocol always sends the data on request/response, and the WebSockets allows the server to send the data to the web browser or the client, even without any request from the browser. HTTP Protocol always use long polling, but Websockets overcomes this problem. At first, the client and the server interacts with HTTP, then the connection upgrades to the WebSocket, providing full duplex communication unlike HTTP. The WebSocket enables the communication from the web browser (client) to the server, in which you can send some data or a real-time data to the client from the server or even bidirectional. It uses HTTP as a intial connection establishment.

WebSocket is one of the communication protocols which provides full duplex communication over a single TCP/IP connection.
