Created
June 13, 2012 14:21
-
-
Save a-bx/2924378 to your computer and use it in GitHub Desktop.
Using Universal Websocket Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//configure websocket servers | |
var ws_servers = [ | |
{ host: "socket1.example.com", | |
port: "8080"}, | |
{ host: "socket2.example.com", | |
port: "8080"}]; | |
//connect to any server | |
//(recconect and time are optional) | |
WSClient = new RhybooWS({ | |
ws_servers: ws_servers, | |
reconnect: true, | |
_reconnection_time: 5000 | |
}).connect(); | |
//Subscribe to channel A | |
WSClient.subscribe("channel_a", function(data) { | |
console.log('receive data from channel A'); | |
console.log(data); | |
WSClient.unsubscribe("channel_a"); //dont receive more messages on this channel | |
}); | |
//Subscribe to channel B | |
WSClient.subscribe("channel_B", function(data) { | |
console.log('receive data from channel B'); | |
console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment