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

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 it works in practice.

For example, how does the phone “know” that it has a new email if it does not 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? Do php classes etc. exist there?

+4
source share
2 answers

For example, how does the phone “know” that it has a new email if it does not manually check the server for a new message?

PUSH implementations vary by protocol, but the principles remain the same. A connection is maintained between the client and the server, and the client is notified by the server of new events. This uses less bandwidth and usually leads to faster interaction than the client periodically asking the server if any new events are expected.

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

  • The client registers with the email server as usual.
  • During the login process, the server reports that it is capable of IDLE .
  • The client checks and downloads new messages as usual.
  • Instead of periodically polling for new messages, the client issues an IDLE command.
  • The session between the server and the client remains calm.
  • When new mail arrives, and the server notifies that the messages are EXISTS .
  • The client can then exit IDLE mode with DONE and download these messages.
  • Repeat step 4.
+8
source

I assume you are talking about an HTTP client? This is usually done using a push server or Comet . Instead of just closing the HTTP connection after the downloaded pages, clients support the connection, open to receive server push messages.

Check out this SO> entry for details on how to do this using jQuery.

There are several examples on the Internet for PHP , although you can look at cometd if you expect more than just a few connections, otherwise you may encounter Apache server connections.

+3
source

All Articles