Similar microblogging I do not refresh the page, and then notify the private message, comments and so on, this function is how to achieve it?

Source: Internet
Author: User
Similar microblogging I do not refresh the page, and then notify the private message, comments and so on, this function is how to achieve it?
Before I heard that we could use long polling, is there any better way? Thank you.

Reply content:

Similar microblogging I do not refresh the page, and then notify the private message, comments and so on, this function is how to achieve it?
Before I heard that we could use long polling, is there any better way? Thank you.

You can use WebSocket, here's an example of a web message push
Https://github.com/walkor/web-msg-sender

Ajax, long connection. Downstairs continue to add

Generally there are 2 ways:
The first is the client (browser) through polling every time the server (Ajax request), belonging to the pull mode, there is a use of WebSocket and server to maintain long links, the server when there is an update to push the message to the client, belonging to the push way, However, this approach requires the support of newer browsers.
According to the actual situation of the project, to choose the right way of implementation.

Linux to open a daemon, when the message is successful when the message ID is written to the Redis queue, the daemon specifically monitors the Redis queue, as long as a message can be pop-up reminders, real-time reminders

WebSocket
Downstairs please Add.

Please refer to this:
http://segmentfault.com/q/1010000002793033/a-1020000002793276

When the tab is activated, the back end of the request, there is an update to display the corresponding prompt.
The request detection status is then sent every 30 seconds.

1, H5 websocket
2, Ajax,commet long connection.
Comet, a "server push" technology based on HTTP long connections, is a new WEB application architecture. Colleagues say Sina Weibo is the technology used;
There's a simple introduction.
Http://www.cleey.com/blog/single/id/707.html
http://www.ibm.com/developerworks/cn/web/wa-lo-comet/

WebSocket a bit wasteful, can use SSE

Ajax timed polling implementation should be the simplest, the server does not have to make big changes, although many people think this is inefficient, but the individual think that based on the HTTP stateless implementation of high concurrency is still possible, the server can reasonably notify the browser based on the system load time of polling interval.

It is also reasonable to poll the push function every 5 minutes. The chat feature is not too long to poll every 5 seconds. The browser can be programmed with JS, if the continuous n times every 5 seconds polling data is empty, you can change to polling every 1 minutes. If the specified time is exceeded (the page loses focus for a long time), the page has no action , you might consider turning off polling.

Sina Weibo chat function should use is comet long polling, the browser sends a request to the server, the server gets the request to enter the poll (even if is the event drive, also has the expense), has the message to return to the browser, Sina Weibo chat Comet server appears to use is jetty (Java) realizes the :
Curl-i http://im.weibo.com/
Server:jetty (9.2.9.v20150224)
Feeling comet is polling the browser and moving to the server side to poll.

Http://www.w3school.com.cn/html5/html_5_serversentevents.asp

Upstairs is very comprehensive, just a whim, the private message notification set to an IFRAME, set Meta refresh also line

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.