Skip to content

Repository files navigation

socket.io-json-parser

An alternative to the default socket.io-parser, encoding and decoding packets with JSON.parse / stringify.

With that parser, binary data (ArrayBuffer / Buffer / Blob / File) is not supported.

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

See also:

Usage

constio=require('socket.io');constioc=require('socket.io-client');constcustomParser=require('socket.io-json-parser');constserver=io(PORT,{parser: customParser});constsocket=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:

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

More information about the exchange protocol can be found here.

About

socket.io parser based on JSON.stringify / JSON.parse

Topics

Resources

Stars

14 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages