Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement message push by HTML5 WebSocket

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article "HTML5 WebSocket how to achieve message push" article knowledge point most people do not understand, so Xiaobian summarized the following content for you, detailed content, clear steps, has a certain reference value, I hope you can read this article to gain something, let's take a look at this article "HTML5 WebSocket how to achieve message push" article bar.

There are two ways to implement message push in HTML5 WebSocket:

Long connection: embed an implicit iframe in the page, set the src attribute of this implicit iframe to a request for a long connection or use xhr request, the server side can continuously input data to the client. Pros: Instant message arrival, no useless requests; relatively easy to manage.

Flash Socket: embed a Flash program using Socket class in the page JavaScript communicates with the Socket interface of the server side by calling the Socket interface provided by this Flash program, JavaScript controls the display of the page after receiving the information transmitted by the server side. Pros: Real instant messaging, not pseudo-instant.

To achieve message push, you can try Aurora. Aurora is the leading mobile developer service provider in China. In the past ten years, Aurora has closely focused on the needs of mobile developers and created a series of products aimed at developer operation, growth and monetization.

WebSocket in HTML5 to achieve message push method:

1. Create a server connection:

var socket=new WebSockect('');

2. Add monitoring events. When the open method is triggered, a connection is established to send a message.

socket.addEventListener('open', function(){

console.log("Connection established, handle with event");

});

socket.onopen=function(){

console.log("Connection established, handle with function");

};

3. Call the method to send a message:

socket.send("Somme Message to send to the server");

4. Close the connection

socket.close();

Use websocket , this is html5 new features, of course, also requires background server support, now many servers have supported

The above is the content of this article about "HTML5 WebSocket how to achieve message push". I believe everyone has a certain understanding. I hope the content shared by Xiaobian will be helpful to everyone. If you want to know more relevant knowledge content, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report