JavaScript-Want to do a similar to the QQ Web version chat function, how to achieve??

Source: Internet
Author: User
Tags pear
When making web chat tools, how do you usually use real-time message delivery?

All I know:

    1. Ajax polling (all say wasted resources, bad ...) )

    2. EventSource (support is not good, IE is not supported at all.) )

    3. Websoket (not very well known ...) )

Moreover, Baidu after the search learned that in the browser does not support WebSocket case, incredibly there is a third-party library to achieve WebSocket, whether the so-called WebSocket is like EventSource, the core principle is to use Ajax polling way to achieve instant communication??

What is the current ubiquitous web-site real-time communication technology? Small white for advice, ask the big God airborne ...

Reply content:

When making web chat tools, how do you usually use real-time message delivery?

All I know:

    1. Ajax polling (all say wasted resources, bad ...) )

    2. EventSource (support is not good, IE is not supported at all.) )

    3. Websoket (not very well known ...) )

Moreover, Baidu after the search learned that in the browser does not support WebSocket case, incredibly there is a third-party library to achieve WebSocket, whether the so-called WebSocket is like EventSource, the core principle is to use Ajax polling way to achieve instant communication??

What is the current ubiquitous web-site real-time communication technology? Small white for advice, ask the big God airborne ...

Workerman is a purely PHP developed, open source, high-performance PHP socket server framework. is widely used in mobile phone app, hand tour service, network game server, chat room server, hardware Communications Server, smart home, car networking, Internet of things and other fields of development. Support TCP long connection, support WebSocket, HTTP and other protocols, support custom protocol. Based on the Workerman developers can focus more on business logic development, no longer for the PHP socket underlying development and worry.
Git repository: Https://github.com/walkor/Wor ...
Chinese home: http://www.workerman.net/
English Document: http://doc3.workerman.net/

The Lord can try this.

Said two PHP scheme, one of the Workerman has been said, the other is swoole based on the development of Phpwebim.

The pecl extension Swoole supports the use of PHP to write high-performance socket applications:

apt-get install php-pear php5-devyum install php-pear php-develpecl remote-info swoolepecl install swoole

Phpwebim is the Swoole official WebSocket Web Instant Chat tool based on the PHP swoole extension and swoole framework development.
Phpwebim supports Websocket+comet two kinds of protocols, which can be used for all kinds of browsers including IE, see demo.

You can also use Ajax polling if you are only implementing a more real-time message notification:
1) single page (polling only on one page)
2) setinterval interval Passive Polling (keep-alive persistent connection, e.g. 30 seconds)
3) Window.onfocus window receives focus active trigger (Event-driven)
The polling interval is too short and the user opens too many pages, which can cause the server to be under a lot of stress.
For businesses with low-real-time requirements, you can increase the time interval, such as polling 1 times in 2 minutes.

window.onblur  = function() {document.title = '失去焦点';};window.onfocus = function() {document.title = '获得焦点';};

I used to write a nodejs Socket.io, direct search, there are many other people to write examples: http://www.open-open.com/lib/...

Upstairs positive solution.

Case Address: http://www.workerman.net/

WebSocket must not have been implemented by Ajax.
With WebSocket is certainly the most perfect, can be achieved through Workerman, react, swoole such framework.
It is possible to use long polling, but it is more resource-intensive. But the realization cost is lower than websocket.
There is real-time polling, the implementation of the lowest cost. But the efficiency is certainly the lowest, like SF's message reminder is uses the timed polling

  • 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.