Socket
Socket
Sign inDemoInstall

binary-socket

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

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
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Binary Socket

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

Package last updated on 02 Oct 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc