java - How are the instant messaging system and push notification system implemented?
PHP中文网
PHP中文网 2017-06-12 09:27:28
0
6
819

How to forward a message to the specified other end through the server

If it is convenient, post a typical code

In addition, what information is stored when the session is stored?

PHP中文网
PHP中文网

认证0级讲师

reply all (6)
黄舟

My understanding:
The client makes a request (sends a request) to the server every interval (such as one second).
If there is a message on the server, the information is marked in the response (response) to notify the client that there is a new message on the server.
The client sends a request to the server to pull the message, and the server responds.

request: Any new news? Please reply if received.
response:No.
request: Any new news? Please reply if received.
response:No.
request: Any new news? Please reply if received.
response: Yes, the message ID is 123456.
request: Please send the message content with message ID 123456.
response: Message id: 123456, message text: Surprise! This woman actually did such a thing in front of 1.3 billion people...

    迷茫

    Message transmission is obtained by refreshing the client to the server instead of the server sending it directly to the client

    In the past, there were indeed some cases where the server directly opened a port locally and the server directly requested the client, but now it is rare to use it for message push (usually used to transfer files or information within the LAN)

    The session is stored on the server, and the name and id of the SESSION are stored locally through Cookies. The server uses these two to obtain the content stored on the server side

      滿天的星座

      There are currently two common solutions.
      1. The client actively polls (that is, it asks the server every N times if there is any news.
      2. The server actively pushes. Sockets are used between back-end services, and websockets can be used to communicate with the front-end.

        女神的闺蜜爱上我

        http2.0 can handle it very well, you can try it~

          曾经蜡笔没有小新

          It is said that it is instant, and a long connection must be established. Such as socket.

            给我你的怀抱

            If it is just one of the many functions of the product, instant messaging recommends that the subject connect to IM, which can save a lot of development expenses. The functions provided by the existing IM providers are relatively comprehensive, and it is much more cost-effective than developing it yourself. You can take a look at the environmental information http://www.easemob.com/

              Latest Downloads
              More>
              Web Effects
              Website Source Code
              Website Materials
              Front End Template
              About us Disclaimer Sitemap
              php.cn:Public welfare online PHP training,Help PHP learners grow quickly!