0.0.2 • Published 7 years ago

ssocks v0.0.2

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

simple sockets js

really simple sockets library. wrapper around net with some basic handling built in.

Build Status

usage

const ssock = require("ssocks");

const socket = ssock({
  port: 9999,     // port to listen on, default 3000
  parser: false,  // use inbuilt simple parser, default true
  quiet: true,    // don't be verbose, default true
});

socket.onMessage((data, conn) => {}); // successfully received message from client
socket.onError((data, conn) => {});   // encountered error

note: all configuration parameters are optional.

default parser

the default parser requires clients to message in the format:

[eventType, eventData] // ["hello", { name: "John Doe" }]

it parses and passes the incoming data to the outgoing functions (onMessage, onError) as:

{
  type: eventType,
  data: eventData,
}