Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nssocket

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nssocket

An elegant way to define lightweight protocols on-top of TCP/TLS sockets in node.js

  • 0.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3M
increased by35.14%
Maintainers
2
Weekly downloads
 
Created

What is nssocket?

The nssocket npm package is a utility for creating namespaced, structured, and real-time TCP and UNIX socket connections. It provides an easy-to-use API for managing data transmission over sockets in a structured manner, using JSON to define namespaces and data structures.

What are nssocket's main functionalities?

Creating TCP Servers and Clients

This feature allows users to create TCP servers and clients. The server listens on a specified port and sends messages to connected clients. Clients connect to the server and listen for specific messages.

const nssocket = require('nssocket');

// Creating a TCP server
const server = nssocket.createServer(socket => {
  socket.send(['hello'], 'world');
});
server.listen(6785);

// Creating a TCP client
const client = new nssocket.NsSocket();
client.connect(6785);
client.data(['hello'], data => {
  console.log('Received:', data);
});

Event-driven Communication

This feature demonstrates how nssocket handles event-driven communication between sockets. The server listens for a specific structured message and responds accordingly.

const nssocket = require('nssocket');

const server = nssocket.createServer(socket => {
  socket.data(['status', 'ok'], () => {
    socket.send(['response'], 'Received OK');
  });
});
server.listen(6785);

Other packages similar to nssocket

FAQs

Package last updated on 18 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc