📜 ⬆️ ⬇️

WebSockets in a Rails application

Recently, I was faced with the need to implement a small chat in one of the Rails projects. There are many ways to solve this problem, ranging from periodic server polls using AJAX and ending with the use of off-the-shelf solutions from third-party services. In order to minimize the traffic and response time of the system, it was decided to use the WebSocket API - one of the parts of the HTML 5 standard that allows the server to initiate data transfer without waiting for a client request. Unfortunately, the WebSocket API is supported by a fairly limited number of browsers, including Google Chrome, Safari 5, Mobile Safari in iOS 4.2 and higher, and perhaps everything (if I am mistaken, correct me in the comments). Of course, this is not enough for a combat application, so you need to offer a backup option for browsers without native support for the WebSocket API. The most convenient way is to use Flash Sockets. Using the WebSocket API and Flash Sockets, the application covers most of the possible cases, including both desktop systems (MS Windows, Linux, Mac OS X) and mobile (Android, iOS).

Let's move from theory to practice, let's talk about what tools allow using WebSocket API in a Rails application. There are several possible options, among which I will note the following:


Summing up, I note that using the WebSockets API improves the interactivity of the web application and makes the resource more convenient, while slightly loading the server, and the Socky-server will make working with the WebSockets API in a Rails application a simple and painless exercise.

')

Source: https://habr.com/ru/post/124672/


All Articles