{"id":14030,"library":"socket.io-msgpack-parser","title":"Socket.IO MessagePack Parser","description":"This package offers an alternative parser for Socket.IO, utilizing the MessagePack format for efficient binary serialization of data instead of the default JSON-based parser. Its primary goal is to minimize message sizes, which is particularly advantageous for applications with high message throughput, though it results in a slightly larger browser bundle (an additional 7.5 KB minified, 3.0 KB gzipped). The current stable version is 3.0.2, which includes TypeScript definitions. The project maintains close compatibility with Socket.IO's protocol versions, requiring a matching parser version on both the server and client (e.g., parser 3.x with Socket.IO 3.x/4.x). This parser differentiates itself by providing a binary-optimized transport layer, a key contrast to the standard `socket.io-parser` and `socket.io-json-parser`.","status":"active","version":"3.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/socketio/socket.io-msgpack-parser","tags":["javascript","typescript"],"install":[{"cmd":"npm install socket.io-msgpack-parser","lang":"bash","label":"npm"},{"cmd":"yarn add socket.io-msgpack-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add socket.io-msgpack-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required on the server-side to configure the Socket.IO instance to use this custom parser.","package":"socket.io","optional":false},{"reason":"Required on the client-side to configure the Socket.IO client instance to use this custom parser.","package":"socket.io-client","optional":false}],"imports":[{"note":"The package exports the parser instance as its default export. For ESM, use a default import. CommonJS `require()` directly resolves to this default export.","wrong":"import { customParser } from 'socket.io-msgpack-parser';","symbol":"customParser","correct":"import customParser from 'socket.io-msgpack-parser';"},{"note":"For CommonJS environments, the `require` statement directly loads the default exported parser instance.","symbol":"customParser (CJS)","correct":"const customParser = require('socket.io-msgpack-parser');"},{"note":"To import the TypeScript type definition for the parser, use a type import. The runtime parser instance is the default export, not a named export `Parser`.","wrong":"import { Parser } from 'socket.io-msgpack-parser';","symbol":"Parser (Type)","correct":"import type { Parser } from 'socket.io-msgpack-parser';"}],"quickstart":{"code":"const io = require('socket.io');\nconst ioc = require('socket.io-client');\nconst customParser = require('socket.io-msgpack-parser');\n\nconst PORT = process.env.PORT || 3000;\n\nconst server = io(PORT, {\n  parser: customParser\n});\n\nserver.on('connection', (socket) => {\n  console.log('Server: Client connected');\n  socket.on('hello', () => {\n    console.log('Server: Received hello from client');\n    socket.emit('world', 'from server');\n  });\n});\n\nconst socket = ioc('ws://localhost:' + PORT, {\n  parser: customParser\n});\n\nsocket.on('connect', () => {\n  console.log('Client: Connected');\n  socket.emit('hello');\n});\n\nsocket.on('world', (data) => {\n  console.log('Client: Received world:', data);\n  socket.disconnect();\n  server.close();\n});\n\nsocket.on('disconnect', () => {\n  console.log('Client: Disconnected');\n});\n\nconsole.log(`Server and client running on port ${PORT}`);","lang":"javascript","description":"Demonstrates how to integrate the MessagePack parser on both the Socket.IO server and client, ensuring consistent message encoding/decoding."},"warnings":[{"fix":"Ensure that `socket.io-msgpack-parser` v3.x is used exclusively with Socket.IO server/client versions 3.x or 4.x. If using older Socket.IO versions (1.x/2.x), you must use `socket.io-msgpack-parser` v2.x.","message":"Version 3.0.0 introduced breaking changes by implementing Socket.IO protocol v5. This makes it incompatible with older Socket.IO server/client versions.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always pass `parser: customParser` to both the `socket.io` server instance and the `socket.io-client` client instance during initialization.","message":"This parser MUST be used on both the Socket.IO server and client sides. Failing to do so will result in connection failures or unhandled protocol errors due to mismatched encoding/decoding strategies.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider the trade-off between smaller message sizes (binary) and initial bundle size. This parser is generally recommended for applications prioritizing network efficiency over minimal initial client footprint.","message":"Using the MessagePack parser increases the browser bundle size compared to the default JSON parser. It adds approximately 7.5 KB (minified) or 3.0 KB (gzipped) to the client-side JavaScript bundle.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'3':98,102 '3.0':62 '3.0.2':70 '7.5':59 'addit':58 'advantag':41 'altern':8 'applic':43 'base':28 'binari':18,112 'binary-optim':111 'browser':55 'bundl':56 'client':95 'close':78 'compat':79 'contrast':118 'current':66 'data':21 'default':25 'definit':74 'differenti':106 'e.g':96 'effici':17 'format':15 'goal':32 'gzip':64 'high':45 'includ':72 'instead':22 'javascript':129 'json':27,127 'json-bas':26 'json-pars':126 'kb':60,63 'key':117 'larger':54 'layer':115 'maintain':77 'match':87 'messag':36,46 'messagepack':2,14 'minifi':61 'minim':35 'offer':6 'optim':113 'packag':5 'parser':3,9,29,88,97,105,123,128 'particular':40 'primari':31 'project':76 'protocol':83 'provid':109 'requir':85 'result':50 'serial':19 'server':93 'size':37 'slight':53 'socket.io':1,11,81,101,122,125 'stabl':67 'standard':121 'though':48 'throughput':47 'transport':114 'typescript':73,130 'util':12 'version':68,84,89 'x':99 'x/4.x':103","created_at":"2026-04-20T01:57:34.103539+00:00","updated_at":"2026-04-20T01:57:34.103539+00:00","problems":[{"fix":"Verify that `socket.io-msgpack-parser` v3.x is paired with Socket.IO v3.x/4.x, or v2.x with Socket.IO v1.x/2.x. Update or downgrade dependencies to ensure compatibility on both ends.","cause":"Socket.IO server and client are using different versions of the protocol, often caused by mismatched `socket.io` and `socket.io-msgpack-parser` versions.","error":"protocol mismatch"},{"fix":"Confirm that both client and server are configured to use `socket.io-msgpack-parser`. Check for any intermediate proxies or network issues that might be corrupting data.","cause":"The parser received data that does not conform to the expected MessagePack or Socket.IO packet structure, typically due to mismatched parsers or corrupted data.","error":"Error: Invalid packet format"},{"fix":"Use `import customParser from 'socket.io-msgpack-parser';` for ESM, or `const customParser = require('socket.io-msgpack-parser');` for CommonJS.","cause":"Incorrect import statement in an ESM or TypeScript environment. The package provides a default export, not a named export that acts as a constructor.","error":"TypeError: customParser is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/socketio/socket.io-msgpack-parser","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/socket.io-msgpack-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}