3

I want to create a facebook-like notification system (the one who appears on the bottom-left side of the screen when someone comment on your post, for example).

The thing here is that the server needs to send you a notification when someone comments in the site in this exactly moment. I think this is called PUSH-System (sorry for my bad english).

I tried with node.JS but my dedicated server can't install it. Only if I buy a very expensive VPS plan.

So, is there a way using jQuery or something like that to make this Push notification system?

Thanks !!

, rodrigo.-

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
rec
  • 192
  • 2
  • 17
  • See these related SO questions: http://stackoverflow.com/questions/7594425/ajax-push-system and http://stackoverflow.com/questions/9138309/php-ajax-jquery-server-push-system – Jeremy Harris Mar 11 '12 at 18:45

2 Answers2

2

If you want a low latency, efficient solution you should use WebSockets. However you need to have fallbacks in place such as long-polling / short polling available if the browser doesn't support WebSockets.

The WebSocket Protocol provides a full-duplex (two way) connection between the server and client. Traditional HTTP is half-duplex (one way). This link will give you an overview of the benefits of using WebSockets vs HTTP: http://www.websocket.org/quantum.html.

You need to be aware that most modern browsers support WebSockets, but use different protocols. See here: What browsers support HTML5 WebSocket API?.

Community
  • 1
  • 1
Jack
  • 15,614
  • 19
  • 67
  • 92
1

In addition to the references I posted in the comments above, implementing a Long Polling technique is a common solution to eliminate large amounts of normal polling. Here is what Wikipedia says about it:

Long polling is a variation of the traditional polling technique and allows emulation of an information push from a server to a client. With long polling, the client requests information from the server in a similar way to a normal poll. However, if the server does not have any information available for the client, instead of sending an empty response, the server holds the request and waits for some information to be available. Once the information becomes available (or after a suitable timeout), a complete response is sent to the client. The client will normally then immediately re-request information from the server, so that the server will almost always have an available waiting request that it can use to deliver data in response to an event. In a web/AJAX context, long polling is also known as Comet programming.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • Thanks i don't understud how Comet work but i will study it soon. Making a request with jQuery AJAX API in a setTimeOut function is bad, right? – rec Mar 11 '12 at 19:14
  • Using Javascript's `setTimeout()` isn't bad as it only runs once and times out. Using `setInterval()` on the other hand, will allow you to make AJAX calls repeatedly on a set time increment. This "polling" can bog down your server and application. That is where "long polling" comes in. You make a single request using Javascript/jQuery and the server holds that connection until it has data which, to a user of the application, appears as though the server just "pushed" the data to the application when really all it did was delay returning the data. – Jeremy Harris Mar 11 '12 at 20:25