socket.io-parser travis-ci npm

2 years after

socket.io-parser

Build Status NPM version

A socket.io encoder and decoder written in JavaScript complying with version 3 of socket.io-protocol. Used by socket.io and socket.io-client.

Parser API

socket.io-parser is the reference implementation of socket.io-protocol. Read the full API here: socket.io-protocol.

Example Usage

Encoding and decoding a packet

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]);
  }
});

Encoding and decoding a packet with binary data

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_EVENTEVENT
    // 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.

License

MIT

Related Repositories

android-websockets

android-websockets

WebSockets (hybi13/RFC) and socket.io client for Android ...

passport.socketio

passport.socketio

access passport.js authenticated user information from socket.io connection ...

tornadio

tornadio

Python socket.io 0.6 server implementation on top of Tornado framework ...

session.socket.io

session.socket.io

Express/connect sessions in socket.io ...

socket.io-protocol

socket.io-protocol

Socket.IO 1.0 Protocol specification and parser component / node.js module. ...


Top Contributors

rauchg kevin-roark darrachequesne nkzawa rase- PeterDaveHello chylli nevir reid gibson042 Nibbler999

Releases

-   2.3.1 zip tar
-   2.3.0 zip tar
-   2.2.6 zip tar
-   2.2.5 zip tar
-   2.2.4 zip tar
-   2.2.3 zip tar
-   2.2.2 zip tar
-   2.2.1 zip tar
-   2.2.0 zip tar
-   2.1.5 zip tar
-   2.1.4 zip tar
-   2.1.3 zip tar
-   2.1.2 zip tar
-   2.1.1 zip tar
-   2.1.0 zip tar
-   2.0.0 zip tar