ssocks
v0.0.2
Published
simple sockets library with no dependencies
Downloads
14
Readme
simple sockets js
really simple sockets library. wrapper around net
with some basic handling built in.
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,
}