Git Product home page Git Product logo

socketcluster-client's Introduction

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);

socketcluster-client's People

Contributors

artema avatar gkze avatar hedgepigdaniel avatar jondubois avatar mattkrick avatar

Watchers

 avatar  avatar

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.