Chapter 7. Networking
Even though a PaaS abstracts away much of the networking complexity, there is still a lot you can do with the network on OpenShift. In this chapter we will cover some of the networking you can do to either make your work easier or add capabilities to your application.
One of the hot new technologies in web applications is the WebSocket protocol. WebSockets allow the client to open a persistent connection to the server. In this way, the server can push information to the client, rather than always having the client pull information from the server. This has a whole host of interesting applications and is much more efficient than using long polling, an alternative technique that simulates two-way communication. Examples of applications this could be used for include:
- Real-time chat applications
- Fleet or vehicle tracking, or any stream of positions
- Multiplayer gaming
- Monitoring applications
- Real-time auction sites
The prerequisites to using WebSockets are:
Your server supports WebSockets. Some examples are:
- Twisted (Python)
- Socky (Ruby)
- Socket (PHP)
- Tomcat7, Netty, and Vert.x (Java and more)
- Using a browser that supports WebSockets, which appears to be all the current browsers.
From there, the basic flow of using WebSockets in your application is:
- The client application makes an upgrade request from HTTP to the WebSocket protocol.
- The server responds that it supports the protocol.
- Away they go, talking over the WebSocket ...