Chapter 3. Web Messaging with STOMP

In this chapter, we will write a web application that sends and receives messages using the STOMP protocol over HTML5 Web Sockets.

In “Locations Application Using STOMP”, we described the Locations application. In this chapter, we will write the web application (shown in Figure 3-1) that consumes the device’s GPS position to display it on a map and send text messages to the device.

Diagram of the +Locations+ Web application
Figure 3-1. Diagram of the Locations web application
Note

Throughout the chapter, we will show all the code required to run the application.

The whole application code can be retrieved from the GitHub repository in the stomp/web/ directory.

HTML5 Web Sockets

Web Sockets is a recent protocol that provides a bidirectional and full-duplex communication channel over a single TCP connection between the web browser and the web server. Before Web Sockets, communication was only one way: the browser initiated communication by sending an HTTP request to the web server, which replied with an HTTP response. The server could not send data to the browser without the browser having first sent a request. Some techniques exist to provide a bidirectional HTTP (such as HTTP long polling and HTTP streaming), but they have significant issues, as described in RFC-6202.

Thanks to HTML5 Web Sockets, it is now possible to have two-way communication between the browser and the server. The ...

Get Mobile and Web Messaging now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.