Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/socketio/socket.io-msgpack-parser
Socket.IO parser based on msgpack
https://github.com/socketio/socket.io-msgpack-parser
javascript msgpack nodejs socket-io socket-io-parser websocket
Last synced: 11 days ago
JSON representation
Socket.IO parser based on msgpack
- Host: GitHub
- URL: https://github.com/socketio/socket.io-msgpack-parser
- Owner: socketio
- License: mit
- Created: 2017-02-21T06:51:13.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2023-06-20T22:52:55.000Z (over 1 year ago)
- Last Synced: 2024-10-29T14:58:26.727Z (3 months ago)
- Topics: javascript, msgpack, nodejs, socket-io, socket-io-parser, websocket
- Language: JavaScript
- Homepage: https://socket.io/docs/v4/custom-parser/
- Size: 110 KB
- Stars: 64
- Watchers: 2
- Forks: 9
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
# socket.io-msgpack-parser
An alternative to the default [socket.io-parser](https://github.com/socketio/socket.io-parser), encoding and decoding packets with [msgpack](http://msgpack.org/).
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:
- the default parser: https://github.com/socketio/socket.io-parser
- a parser based on JSON.stringify/parse: https://github.com/darrachequesne/socket.io-json-parserCompatibility table:
| Parser version | Socket.IO server version |
|----------------| ------------------------ |
| 2.x | 1.x / 2.x |
| 3.x | 3.x / 4.x |## Usage
```js
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:
```json
{
"type": 2,
"nsp": "/",
"data": ["hello", "you"]
}
```which will be encoded by the parser as:
``
More information about the exchange protocol can be found [here](https://github.com/socketio/socket.io-protocol).