Skip to content

Instantly share code, notes, and snippets.

@a-bx
Created June 13, 2012 14:21
Show Gist options
  • Save a-bx/2924378 to your computer and use it in GitHub Desktop.
Save a-bx/2924378 to your computer and use it in GitHub Desktop.
Using Universal Websocket Client
//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