Giter VIP home page Giter VIP logo

jquery.websocket's Introduction

jquery.WebSocket

jquery.WebSocket enables WebSocket support for all Browsers. In older Browsers the WebSocket is emulated by using AJAX Long Polling as fallback. But all instances of WebSocket providing the same interface and the same events! So no need to worry about writing application code based on WebSockets and it's events like onmessage, onclose ...

One simple interface $.WebSocket(url, protocol, options); thats it. The same interface as current native WebSocket implementation. The same native events (onopen, onmessage, onerror, onclose) + custom event onsend.

But jquery.WebSockets adds some nice features:

[x] Multiplexing - Use a single socket connection and as many logical pipes within as your browser supports. All these pipes are emulated WebSockets also with the same API + same events! Use each pipe as WebSocket! But this requires you to implement the protocol on this level of communication The data is en- + decoded in a special way to make multiplexing possible

[x] Interface for adding protocol to manipulate data before they are send and right after they arrive before event onmessage is fired!

example:

// The WebSocket-Object (with resource + fallback)
var ws = $.WebSocket ('ws://127.0.0.1:9300', null, {http: 'http://127.0.0.1:81/Lab/Websocket/Data/poll.php'});                                              

// WebSocket onerror event triggered also in fallback
ws.onerror = function (e) {
    console.log ('Error with WebSocket uid: ' + e.target.uid);                                                                                              
};                                                                                                                                                          

/**
 * demonstrate multiplexing
 */
var pipe1;                                                                                                                                                  

// if connection is opened => start opening a pipe (multiplexing)
ws.onopen = function () {
    //
    pipe1 = ws.registerPipe ('user/all', null, {
        onopen: function () {
            console.log ('pipe1 (' + this.uid + ') connected!');                                                                                            
        },
        onmessage: function (e) {
            console.log ('< pipe1 : ' + e.data);                                                                                                            
        },
        onerror: function (e) {
            console.log ('< pipe1 error : ' + e.data);                                                                                                      
        },
        onclose: function () {
            console.log ('pipe1 (' + pipe.uid + ') connection closed!');                                                                                    
        }
    });                                                                                                                                                     
};  

jquery.websocket's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.