Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing messages to clients from a server-side application?

I have a javascript-based client that is currently polling a .NET web service for new content. While polling works...I'm not happy with this approach because I'm using system resources and creating overhead when there aren't any changes to receive.

My question is how do I notify my client(s) that there is new content for it to display? I am open to on any additional technologies I would have to implement this solution with.

like image 905
Achilles Avatar asked Aug 04 '10 18:08

Achilles


People also ask

How do I push client/server notifications?

At a high-level, the key steps for implementing push notifications are: Adding client logic to ask the user for permission to send push notifications, and then sending client identifier information to your server for storage in a database. Adding server logic to push messages to client devices.

Can a server send request to client?

HTTP Basics As a quick summary, the HTTP/1.1 protocol works as follows: The client (usually a browser) opens a connection to the server and sends a request. The server processes the request, generates a response, and closes the connection if it finds a Connection: Close header.

How do I use push notifications on web application?

Send push messages Normally, this would require sending a subscription from a web page to a backend. The backend would then trigger a push message by making an API call to the endpoint in the subscription. Under Text to Send, add any string you want to send with the push message. Click the Send push message button.


1 Answers

First of all, polling is the way to go. You could do it with Flash or Silverlight or Comet - http://en.wikipedia.org/wiki/Comet_(programming) which can hold a tcp connection open for you for notifications. A webpage itself cannot hold a socket open, so there is no way to directly notify a web client.

[Edit] But think about it, how many client can hold a tcp connection towards one server at a time? For a larger system you would run out of available sockets pretty fast as there are 65k ports available.
How many concurrent connections your server can handle depends on your hardware resources. If you have enough memory and cpu you should be able to handle ~100k and maybe more. But if each request access a database or some other resource over tcp/ip, you could be limited to the number of ports per ip available (65k). You should also have the push requests go against a separate domain, as a browser normally caps to two concurrent connections per domain, so you won't interfere with the normal page loading.

Using polling in combination with cache servers in the front is a good solution. You can have logic on the server which updates the cache per client, reducing the load for each poll. You could update the cache for users who have signed in/polled within the X number of minutes to reduce the cache updating even more. And to me implementing pull is easier than pull, technology wise.

like image 68
Mikael Svenson Avatar answered Sep 20 '22 23:09

Mikael Svenson