🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

socket.io-msgpack-parser

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socket.io-msgpack-parser

socket.io parser based on msgpack

3.0.2
latest
Source
npm
Version published
Weekly downloads
7.9K
-31.08%
Maintainers
1
Weekly downloads
 
Created
Source

socket.io-msgpack-parser

An alternative to the default socket.io-parser, encoding and decoding packets with msgpack.

With that parser, the browser build will be a bit heavier (an additional 7.5 KB minified, 3.0 KB gzipped), but each message will be smaller (sent as binary).

Please note that you MUST use the parser on both sides (server & client).

See also:

Compatibility table:

Parser versionSocket.IO server version
2.x1.x / 2.x
3.x3.x / 4.x

Usage

const io = require('socket.io');
const ioc = require('socket.io-client');
const customParser = require('socket.io-msgpack-parser');

const server = io(PORT, {
  parser: customParser
});

const socket = ioc('ws://localhost:' + PORT, {
  parser: customParser
});

socket.on('connect', () => {
  socket.emit('hello');
});

Format

socket.emit('hello', 'you') will create the following packet:

{
  "type": 2,
  "nsp": "/",
  "data": ["hello", "you"]
}

which will be encoded by the parser as:

<Buffer 83 a4 74 79 70 65 02 a3 6e 73 70 a1 2f a4 64 61 74 61 92 a5 68 65 6c 6c 6f a3 79 6f 75>

More information about the exchange protocol can be found here.

FAQs

Package last updated on 14 Nov 2022

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