Simple Socket
This is a lightweight wrapper around the Node.js Socket
class that makes reconnecting and handling errors super simple. It works with net
and tls
.
Installation
$ npm install simple-socket
Usage
var Socket = Socket; var socket = host: 'localhost' port: 80; ; { socket; { if err console; console; ; // reconnect when the socket is disconnected socketonDisconnect = connect; // reconnect when there is a socket timeout socket { // set onDisconnect to null before disconnect // if you don't want to reconnect // socket.onDisconnect = null; // disconnect clears all state and onDisconnect will // get called socket; }; // handle incoming data socket { // socket.writeable() will return false if the socket is // disconnected or the underlying socket is not writable if socket // socket.write() will callback with an error // (close events before drain are treated as an error) socket; }; // socket.pipe(destination) is also available };};