Socket
Book a DemoInstallSign in
Socket

jcom

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jcom

A super awesome TCP/IPC module that supports JSON messages.

latest
Source
npmnpm
Version
0.1.14
Version published
Weekly downloads
23
4.55%
Maintainers
1
Weekly downloads
 
Created
Source

jcom

A super awesome TCP/IPC module that supports JSON messages.

Work In Progress!

This module needs some refinements before it can be used in production.

Quick Start

On the server:

const { JcomServer } = require(`jcom`);

const server = new JcomServer(`unique-server-identity`, `tcp`);

server.onMessage(`awesome-message`, async (client, message) => {
	/* await doSomethingCool(message); */
});

await server.listen(`127.0.0.1:5728`);

await server.broadcast([ `dingos`, `ducks` ], `some-message-type`, {
	hello: `world`,
});

const allClients = server.getClients();

await server.send(allClients, `some-message-type`, {
	hello: `world`,
});

On the client:

const { JcomClient } = require(`jcom`);

const client = new JcomClient(`some-unique-client-id-string`, `tcp`, {
	groups: [ `ducks`, `dogs`, `dingos` ],
});

client.onMessage(`some-message-type`, async message => {
	/* await doSomethingEvenCooler(message); */
});

await client.connect(`127.0.0.1:5728`);

await client.send(`awesome-message`, {
	some: `data`,
	number: 1
});

await client.broadcast([ `dogs` ], `awesome-message`, {
	some: `data`,
	number: 1
});

Reserved Message Types

The following message types are reserved and should not be used by your code:

  • jcom/server-ready - Server emits this event to newly connected clients when its ready to accept further messages.
  • jcom/identification - Client emits this event after connecting to a server to identify itself.
  • jcom/client-broadcast - Client emits this event to a server when it wants to broadcast to other clients.

Keywords

jcom

FAQs

Package last updated on 07 Feb 2019

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