Skip to content

Using MessagePack (binary frames) with SocketCluster #64

Description

@melv-n

Currently the SocketCluster client uses a format of:

{"event":"someType","data":{"foo":"bar"},"cid":3}

The format has considerable overhead on the messaging structure and I was wondering how we could go about implementing a buffered-approach such as MessagePack. This could save us big on bandwidth as we're developing an application with a high rate of message throughput.

Right now I'm trying something like:

/**
 * Send a Message to Remote over WebSocket.
 * Note: This method is part of an abstracted Transport layer used by both Client and Server
 */
send(messageType, message, callback = null) {
  // this.socket = SocketCluster socket

  if (this.socket.getState() !== 'open') {
    return;
  }

  const encoded = msgpack.encode({event: messageType, data: message}); // returns Buffer

  // Get the SocketCluster Transport and send Binary frame
  if (this.socket.transport) { // SCClient Socket
    this.socket.transport.socket.send(encoded);
  } else { // SCServer Socket
    this.socket.socket.send(encoded);
  }

  // The original SocketCluster way which reproduces a "heavy" json string-payload
  this.socket.emit(messageType, message);
}

What do you think of supporting raw binary frames directly? And if there's no interest in official support, could you share your thoughts on this? Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions