
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
socket.io-parser
Advanced tools
A socket.io encoder and decoder written in JavaScript complying with version 5
of socket.io-protocol.
Used by socket.io and
socket.io-client.
Compatibility table:
| Parser version | Socket.IO server version | Protocol revision |
|---|---|---|
| 3.x | 1.x / 2.x | 4 |
| 4.x | 3.x | 5 |
socket.io-parser is the reference implementation of socket.io-protocol. Read the full API here: socket.io-protocol.
var parser = require('socket.io-parser');
var encoder = new parser.Encoder();
var packet = {
type: parser.EVENT,
data: 'test-packet',
id: 13
};
encoder.encode(packet, function(encodedPackets) {
var decoder = new parser.Decoder();
decoder.on('decoded', function(decodedPacket) {
// decodedPacket.type == parser.EVENT
// decodedPacket.data == 'test-packet'
// decodedPacket.id == 13
});
for (var i = 0; i < encodedPackets.length; i++) {
decoder.add(encodedPackets[i]);
}
});
var parser = require('socket.io-parser');
var encoder = new parser.Encoder();
var packet = {
type: parser.BINARY_EVENT,
data: {i: new Buffer(1234), j: new Blob([new ArrayBuffer(2)])},
id: 15
};
encoder.encode(packet, function(encodedPackets) {
var decoder = new parser.Decoder();
decoder.on('decoded', function(decodedPacket) {
// decodedPacket.type == parser.BINARY_EVENT
// Buffer.isBuffer(decodedPacket.data.i) == true
// Buffer.isBuffer(decodedPacket.data.j) == true
// decodedPacket.id == 15
});
for (var i = 0; i < encodedPackets.length; i++) {
decoder.add(encodedPackets[i]);
}
});
See the test suite for more examples of how socket.io-parser is used.
MIT
This package is part of the Engine.IO library, which is a lower-level component of the Socket.IO framework. It provides similar encoding and decoding functionalities for the Engine.IO protocol, which is a bit more focused on the transport layer compared to the higher-level abstraction provided by socket.io-parser.
While not a direct alternative to socket.io-parser, the 'ws' package is a popular WebSocket library for Node.js that allows for sending and receiving data over WebSockets. It handles the WebSocket protocol directly, without the additional features and abstractions that Socket.IO provides.
json-socket is a wrapper around the Node.js net library that adds a layer for seamless JSON message sending and receiving. It's similar to socket.io-parser in that it deals with message serialization and deserialization, but it's tailored for use with raw TCP sockets rather than the Socket.IO protocol.
FAQs
socket.io protocol parser
The npm package socket.io-parser receives a total of 9,242,420 weekly downloads. As such, socket.io-parser popularity was classified as popular.
We found that socket.io-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.