2.2.6 • Published 9 years ago

sc2-client v2.2.6

Weekly downloads
164
License
-
Repository
github
Last release
9 years ago

SocketCluster Client

SocketCluster Client is the client-side component of SocketCluster.

To install, run:

npm install socketcluster-client

The socketcluster-client script is called socketcluster.js (located in the main socketcluster-client directory)

  • You should include it in your HTML page using a <script> tag in order to interact with SocketCluster.

To build SocketCluster Client with browserify, use:

browserify -s socketCluster index.js > socketcluster.js

How to use

Embed in your HTML page using (Note that the src attribute may be different depending on how you setup your HTTP server):

<script type="text/javascript" src="/socketcluster.js"></script>

Once you have embedded the client socketcluster.js into your page, you will gain access to a global socketCluster object. Then, to begin interacting with the SocketCluster cluster, you will need to establish a connection. Once that's done, you will be able to emit events to the server and listen to incoming events (example code):

var options = {
    port: 8000
};

// Initiate the connection to the server
var socket = socketCluster.connect(options);
socket.on('connect', function () {
    console.log('CONNECTED');
});

// Listen to an event called 'rand' from the server
socket.on('rand', function (num) {
    console.log('RANDOM: ' + num);
    var curHTML = document.body.innerHTML;
    curHTML += 'RANDOM: ' + num + '<br />';
    document.body.innerHTML = curHTML;
});

Example with HTTPS:

var options = {
    protocol: 'https',
    hostname: 'example.com',
    port: 443
};

// Initiate the connection to the server
var socket = socketCluster.connect(options);
2.2.6

9 years ago

2.2.5

9 years ago

2.2.4

9 years ago

2.2.3

9 years ago

2.2.1

9 years ago

2.2.0

9 years ago

2.1.9

9 years ago

2.1.8-alpha

9 years ago

2.1.7

9 years ago

2.1.6

9 years ago

2.1.5

9 years ago

2.1.3

9 years ago

2.1.2

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.27

9 years ago

2.0.26

9 years ago

2.0.24

9 years ago

2.0.23

9 years ago

2.0.22

9 years ago

2.0.21

9 years ago

2.0.20

9 years ago

2.0.19

9 years ago

2.0.18

9 years ago

2.0.17

9 years ago

2.0.16

9 years ago

2.0.15

9 years ago

2.0.14

9 years ago

2.0.13

9 years ago

2.0.12

9 years ago

2.0.10

9 years ago

2.0.9

9 years ago

2.0.8

9 years ago

2.0.7

9 years ago

2.0.6

9 years ago

2.0.5

9 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.0

9 years ago