Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does push email/chat work? Can it be implemented easily for small websites?

I am trying to understand how push services work. I believe push notifications are where the server 'pushes' a new item to the client, but I don't know how that works in practice.

For example, how does a phone "know" that it has a new email to pick up if it doesn't manually check the server for a new message?

Also, how can this be implemented for a chat program or notification system for a small website? Are there php classes out there, etc..?

like image 487
chris Avatar asked Dec 22 '22 08:12

chris


2 Answers

For example, how does a phone "know" that it has a new email to pick up if it doesn't manually check the server for a new message?

PUSH implementations vary, depending on the protocol, but the principles remain the same. A connection is kept open between the client and server and the client is notified by the server of new events. This utilises less bandwidth and typically leads to faster interaction than the client periodically asking the server whether there are any new events waiting.

As a demonstration, this is how PUSH IMAP (known as IDLE) mail works:

  1. The client logs into the email server as normal.
  2. During the login process the server advertises that it is capable of IDLE.
  3. The client performs a check and download of new messages as normal.
  4. Instead of periodically polling for new messages the client issues an IDLE command.
  5. The session between the server and client remains quiet.
  6. When new mail arrives and the server notifies that the messages EXISTS.
  7. The client can then exit IDLE mode with DONE and download those messages.
  8. Repeat from step 4.
like image 145
Dan Carley Avatar answered Mar 01 '23 22:03

Dan Carley


I'm assuming you are talking about an HTTP client? It is generally done with Server push or Comet technology. Instead of simply closing the HTTP connection after a page loaded clients keep the connection open to receive server push messages.

Have a look at this SO entry for some details on how to do it with JQuery.

There are some examples for PHP on the web although you might want to look at a cometd server if you expect more than just a handful of connections otherwise you might run out of Apache server connections.

like image 32
leonm Avatar answered Mar 02 '23 00:03

leonm