Home Development of Websites Simple real-time communication with the visitor

Simple real-time communication with the visitor

by admin

I’ve been interested in Web in real time.There are already a number of libraries for this today. In this thread I want to talk about the easiest way we tried recently: using the external service Pusher.com.
If sending a message asynchronously to the server is easy today, then backhaul is not so rosy yet. The service is just taking over this task.
Simple real-time communication with the visitor
It all works very simply. Pusher JavaScript is inserted into the page, it opens a connection to the pusher servers and subscribes to messages through some channel. When you want to send a message, you call the pusher API and send the message to the channel. All users who subscribe to the channel will receive it.
In this way you can very easily organize mass mailing of messages to all needed users online. What makes it very easy to create a chat room – just insert pusher on the page, the script on your server will receive messages POST-, "pull" API Pusher `a, and he will send them to all customers through web sockets. You can also do more advanced stuff like collaborative graphical editors – everything is in examples and documentation
From my point of view – a few months ago we moved the chat and online to a pusher, thereby solving several problems at once :
– significantly speeded up message delivery
– Reduced user traffic
– reduced load on our servers – now we only accept messages, and pusher does the mailing to users
– improved system scalability
There were some doubts when we switched, whether users would encounter problems. How well different browsers will be supported. The fears were in vain – the pusher uses WebSockets, and when they are not available (e.g. in ancient non-browser IE) good old emulation via Flash Sockets – exactly what I used in my model Websocket chat. Practice has shown that this is enough. There is no need to complicate and degrade to Long Polling, Multi Part and other things.
We recently decided to use it in another more complex project.
If interested, I’ll describe it in detail as we implement it.

To summarize

Pros :
– Very easy to connect to a website – there are ready-made PHP and Python libs
– if you don’t have any libs for your language, you can use a simple API – curl`a is enough for this
– removes the scaling problem – the pusher is hosted on Amazon servers
Minuses :
– paid

You may also like