Socket
Socket
Sign inDemoInstall

binary-socket

Package Overview
Dependencies
85
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    binary-socket

Simple Binary Sockets to use, builded on thoroughly tested modules, standards and it's easy to integrate.


Version published
Maintainers
1
Install size
12.3 MB
Created

Readme

Source

Binary Socket

Simple Binary Sockets for node & web, ready to use, builded on thoroughly tested modules, standards. Sockets are easy to integrate.

Installation


npm install binary-socket --save

Server

import {SocketServer} from 'binary-socket';

const wss = new SocketServer({});

wss.on('connection', function connection (client) {
    client.on('stream', (stream, meta) => onStreamHandler({stream, meta, onStream, client}));
});
wss.on('error', err => console.error('SocketServer Error:', err));

Client

import {SocketClient} from 'binary-socket';

const client = new SocketClient('ws://www.myhost.com/path');

client.on('open', () => {
     const stream = client.createStream({someKey: 'some value'});
});
client.on('error', err => console.error(err));

Sharing Server with other sockets

const WS = require('ws');
const server = new WS.Server({server: httpServer, path});
const handleUpgrade = server.handleUpgrade.bind(server);
server.handleUpgrade = function upgradeRouter (req, ...params) {
    if (req.url === path) {
        return handleUpgrade (req, ...params);
    }
};
wss = new SocketServer({
    server
});

About

  • Binary data is serialized according to MessagePack v5 specification.
    • Message format:
 [command, payload, streamId]
 
 New stream
 [ 'n'  , Meta , new streamId ]
 
 Data
 [ 'd'  , Data , streamId ]

 Pause
 [ 'p'  , null , streamId ]

 Resume
 [ 'r'  , null , streamId ]

 End
 [ 'e'  , null , streamId ]

 Close
 [ 'c'  , null , streamId ]
  • Server Side Sockets works at the top of ws package (a Node.js WebSocket library)

FAQs

Last updated on 09 Mar 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc