Very nice web front-end technology

2010-12-04  来源:本站原创  分类:Web  人气:125


web socket implementations heartbeat package 05/30/2010

Now the complex network environment, socket package is to get healthy and strong heart connection to an effective solution, today, we will implement in the web socket heartbeat package program, yes, even though we just do a simple chat room, but we let him stable reliable number is also not wrong.

My heart is a simple package solution, the principle is the heartbeat interval to send packets of data to the server, the server sends back a certain period of time response to heartbeat packets, compared to time-out limit, if more than the set timeout, the server is that the current websocket connection has been disconnected, close the current web socket connection, handled, such as re-connection, or pop-up tips ... ...

Useful core code is like this:

function keepalive( ws ){
        var time = new Date();
        if( last_health != -1 && ( time.getTime() - last_health > health_timeout ) ){
                        // At this point you can think of disconnected, you can set reconnect or to close the connection
                        $("#keeplive_box").html( " The server is not responding ." ).css({"color":"red"});
                $("#keeplive_box").html( " Connect to normal " ).css({"color":"green"});
                if( ws.bufferedAmount == 0 ){
                        ws.send( '~H#C~' );

This is the heart function, sending heartbeat packets and detection of degree of heart health. We will be implanted in the websocket the onopen event, to open the heartbeat detection. Like this:

var ws = new WebSocket( to_url );
                $("#send_btn").attr("disabled", false);
                heartbeat_timer = setInterval( function(){keepalive(ws)}, 1000 );

Yes, this way you can achieve web socket heartbeat package, here are some ways similar to multi-threaded send, sending heartbeat packets at the same time, does not affect the normal data communication, or more times in our example the websocket chat rooms improvements, we can find the heartbeat package is running, and will not interfere with our normal chat. Server I also made some changes, principles similar to that in more than a certain period of time the client did not receive the heartbeat packet sent, then that the client has dropped, close the connection, recover resources.

Demo here:

Now, there is a new problem, if we use php socket to simulate the heartbeat packet technology, how to achieve? Pleased to meet you passing friends, grateful.

1,449 spaces surrounding shoes | 3 Comments Category: Web front-end programming , Internet 2.0 , network communication protocol label: , ,

  • 10 Web Application Interface Technology 2010-05-10

    Today more and more applications migrate to web platform. Since there is no platform restrictions and installation requirements, SAAS model looks very attractive. Web application interface design, the core is the web design, but its focus is mainly i

  • [Transferred] Web front Performance Optimization 2008-11-16

    JS Answer Center Optimization * The first screen will not appear as JS file * Support parallel downloads * JS files should not be too big * Streamline the JS code * JS files should not be too much * Use gzip compressed JS files The first screen will

  • WEB Front End Optimization Tips 2010-05-01

    First, we pass a Yahoo charts to see Dakai the http traffic data: we can find a page from the first time to issue a request to fully load the server to the client's process, read html code for the entire response time of only 5%, thi

  • Web Development and Technology 2011-05-02

    Transfer from: Douban trees and snow In recent years, has been followed blindly follow technology trends around them, never had to study carefully how the world has this kind of change. Combine their experience and understanding of some of the inform

  • WEB front end of my road 2010-11-27

    Since these days for the project I learned some stuff, write this down and WEB partners for their own reference: First, do the project is not a person's paradise, but need everyone to go forward together. Second, the communication flow is the project

  • gif and jpg web front end of the picture format 2010-10-14

    The need to be able to say face to face with the picture clearly shows I will simply introduce the next gif image is characterized by the edge with the color values are very clear jpg image edge is not clear, his color is the progressive gif for the

  • web development integrated technology 2011-08-25

    1, a bi-directional graph, each node represents a data record, design a database table structure; design algorithms, list all the paths between any two points 2, how to cache data is valid for 30 minutes (each added a new data expires after 30 minute

  • Dynamic Web Development-PHP Web2.0 Technology and Application (PDF eBook) 2010-11-27

    Dynamic Web Development-PHP Web2.0 Technology and Application (PDF eBook) Related books: The book Web 2.0 site development needs and 28 5 important elements for clues, from the development of Web 2.0, PHP three reasons for starting a comprehensive ex

  • Transformation of Java Web Template - fastm 2009-02-08

    1. "Simple is beautiful" utopian (ring) Qu In the field of software design, there is one of well-known words of wisdom - that is simply beautiful. Almost all of the software design masters, will be discipline in his work the reader: "Simple

  • [Change] My FLASH Complex 2010 - and the start of FLASH WEB GAME 2010-03-09

    ★ directory: → I → FLASH WEB GAME development process outlined in today's FLASH WEB GAME game → entrepreneurial companies face the problems and difficulties → FLASH WEB GAME system architecture → FLASH WEB GAME personnel division of the front-end arc

  • I think Microsoft. NET prospect of the technology 2010-04-18

    Original link: 2002 release. NET 1.0, after 8 years of development,. NET development to a 4.0, has become a large and complex software development and operating platform, the increasing co

  • Web front-end programming skills in R & D engineers, the road soaring 2011-05-12

    [Background] If you are just entering the WEB front-end research and development, how deep the lake to try it and see it in this article; If you do a 2023 WEB front-end product development, increase confusion could not find the way, reading this righ

  • Web site performance testing tool 2009-09-15

    With the Web 2.0 technology is developing rapidly, many companies have developed a number of Web-based Web Services , Usually in the design of the development of Web applications when it is very difficult to simulate a large number of users access th

  • Select Flex to connect J2EE technology 2009-10-06

    Flex can be used to connect the javaEE technical background: 1) HTTPService (xml mode) 2) Webservice (soap) 3) Blazeds 4) LiveCycle Data Services 5) Graniteds 6) Flamingo 7) Fiji 8) Fxstruts 9) other open source projects , Respectively, explain: HTTP

  • Flex connection Java EE technology choices 2010-03-29

    Flex can be used to connect the background JavaEE technologies: ◆ HTTPService (xml mode) ◆ Webservice (soap) ◆ Blazeds ◆ LiveCycle Data Services ◆ Graniteds ◆ Flamingo ◆ Fiji ◆ Fxstruts ◆ other open source projects Describe, respectively: HTTPService

  • SOA thinking. Technology and System Integration Application Xiangjie Study Notes (1) 2010-03-29

    Today saw a book, "SOA thinking, technology and systems integration Xiang Jie," the search electronic version of the attempt. Inadvertently see a reading on the book notes, subsequently reproduced the order to leave a mark: SOA, to listen to is

  • Comprehensive program to enhance the performance of Web 2.0 applications, Part 1: Web 2.0 applications, performance analysis overview and new challenges 2008-11-21

    Introduction Usually, when we talk about a performance of Internet applications, we are always concerned about the server system throughput (Throughput), response time (Response Time), units of the affairs of the amount of time (Transactions per seco

  • Comprehensively enhance the performance of Web 2.0 applications, Part 1: Web 2.0 applications, performance analysis overview and new challenges 2010-03-15

    Introduction Usually, when we talk about the performance of an Internet application, we will always be concerned about the server, the system throughput (Throughput), response time (Response Time), the transaction volume per unit time (Transactions p

  • Summary of web UI technologies 2010-07-06

    Summary of web UI technologies [email protected] March 2009 1, Web UI Technology Development 1.1 Web 1.0 in the UI Technology In the HTML specification development process, HTML tags to build the page based Web UI has been the mainstream technology. 1

  • HTML5 Web applications, we look forward to turning gorgeous 2010-07-08

    Hypertext Markup Language HTML is an essential part of building the Internet, but has been formalized since HTML4 standards (October 1997 version 4.0,1999 version 4.01 in October), further development can be said to be intermittent. One direction is