socketty
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/socketty package

0.2.3 • Public • Published

socketty-node

A lightweight, browser compatible, WebSocket API.

Install

With npm:

npm install --save socketty

With bower:

bower install --save socketty

Usage

In node.js:

var socketty = require('socketty');

In a browser:

<script src="/bower_components/socketty/dist/socketty.min.js"></script>

Socketty is also compatible with Browserify. In the browser, only the client API is available, for obvious reasons.

Examples

A basic websocket client in Node:

var socketty = require('socketty');

socketty.connect('ws://localhost:8080', function (socket) {
    console.log('Connected');

    socket.on('hello', function (msg) {
        console.log('Message from server: ' + msg);
    });

    socket.disconnect(function () {
        console.log('Disconnected');
    });
});

A websocket server:

var http            = require('http');
var socketty        = require('socketty');

var server = http.createServer();
var wsServer = socketty.createServer(server);

server.listen(8080);

wsServer.connection(function (socket) {
    console.log('New client');
    socket.send('hello', 'Hello client!');

    socket.disconnect(function () {
        console.log('Client disconnected');
    }); 
});

License

Socketty is distributed under the MIT license.

Readme

Keywords

Package Sidebar

Install

npm i socketty

Weekly Downloads

9

Version

0.2.3

License

MIT

Last publish

Collaborators

  • nax