net-socket.io

1.0.1 • Public • Published

Net Socket IO

Net-Socket.IO enables real-time, bidirectional and event-based communication for low-level IPC and TCP sockets. It is a small wrapper around node's net library, that makes low-level socket programming easy.

Heavily Based on socket.io and Event Emitters.

For more information on the motivation behind this library, check out my blog post on the subject.

Examples

server

const { Server } = require('net-socket.io');
const socketFile = '/tmp/socket'; // file for IPC socket, or port number for TCP socket.
const io = Server(socketFile);
 
io.on('connection', function(socket){
  socket.emit('request', /* */); // emit an event to the socket
  io.emit('broadcast', /* */); // emit an event to all connected sockets
  socket.on('reply', function(data){ /* */ }); // listen to the event
});

client

const { Socket } = require('net-socket.io');
const socketFile = '/tmp/socket';
const socket = Socket(socketFile);
 
socket.on('ready', () => {
  socket.emit('request', /* */);
  socket.on('reply', (data) => { /* */ }); // listen to the event
});

Look in the examples folder for complete examples.

Documentation

Check out the API documentation for more details.

/net-socket.io/

    Package Sidebar

    Install

    npm i net-socket.io

    Weekly Downloads

    12

    Version

    1.0.1

    License

    ISC

    Unpacked Size

    54.4 kB

    Total Files

    24

    Last publish

    Collaborators

    • meech-ward