Socket
Socket
Sign inDemoInstall

@fillipe143/node-socket

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @fillipe143/node-socket

Send packets to other servers using NodeSocket.


Version published
Maintainers
1
Install size
5.68 kB
Created

Readme

Source

NodeSocket

NodeSocket is a library written in Node.js that aims to create WebSocket connections between servers and clients.

Read the docs here

Examples

Look at the examples of server usage in server.js and client usage in client.js. The scripts cover the most common use cases.

Install

Create an NPM project and write to the terminal: npm install @fillipe143/node-socket

Then import the library using

To server:

const { ServerSocket } = require('@fillipe143/node-socket');

To client:

const { ClientSocket } = require('@fillipe143/node-socket');

Create Server

const { ServerSocket } = require('@fillipe143/node-socket');

//http://localhost:3000
const options = {
    host: 'localhost',
    port: 3000
}

const server = new ServerSocket(options);

Connect to Server

const { ClientSocket } = require('@fillipe143/node-socket');

//http://localhost:3000
const options = {
    host: 'localhost',
    port: 3000
}

const client = new ClientSocket(options);

Handling Events

on('connect', () => void): this //When the connection is created
on('error', (err) => void): this //When the connection fails
on('data', (data) => void): this //Receive data from other WebSocket libraries
on('close', () => void): this //When the connection is terminated

Send Data

const { ServerSocket } = require('@fillipe143/node-socket');

const options = {
    host: 'localhost',
    port: 3000
}

const server = new ServerSocket(options);

server.on('connect', () => {
    server.emit('event name', 'event data');
});

Receive Data

const { ClientSocket } = require('@fillipe143/node-socket');

const options = {
    host: 'localhost',
    port: 3000
}

const client = new ClientSocket(options);

server.on('event name', data => {
    console.log('Received: ' + data);
});

Note

Repository: https://github.com/Fillipe143/NodeSocket

Version: 1.0.1

Keywords

FAQs

Last updated on 05 Dec 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc