npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ipc-json-bridge

v0.2.1

Published

A CLI tool to bridge IPC calls to stdio using simple JSON commands.

Downloads

319

Readme

IPC JSON Bridge

LICENSE NPM ISSUES RELEASES

A lightweight, cross-platform CLI tool written in Go that enables seamless IPC (Inter-Process Communication) via JSON messages over Unix domain sockets and Windows named pipes. This tool serves as a simpler, more flexible alternative to node-ipc, with added features like sender PID tracking on Unix systems.

Overview

IPC JSON Bridge CLI acts as a message relay between standard input/output and an IPC socket. It:

  • Accepts JSON messages from stdin and forwards them to connected clients
  • Receives messages from clients and outputs them as JSON to stdout
  • Works across Unix, Darwin, and Windows
  • Supports multiple CPU architectures
  • Provides sender PID information on Unix systems
  • Uses a simple, JSON-based protocol
  • Support server and client mode

Installation

NPM Package

Pre-built binaries are available in the NPM package for easy installation.

npm install ipc-json-bridge

Manual Download

Standalone binaries are also available for direct download from the releases page.

Build from Source

Download the repository, and run the following commands to build the CLI tool from source.

# Download the go dependencies
go mod download

# Build the CLI tool
npm run build:<unix|darwin|windows>:<amd64|arm64|arm|386>

# Or build for all available platforms
npm run build:all

Usage

TypeScript SDK (Recommended)

import { IpcBridge } from 'ipc-json-bridge';

// Initialize the bridge
const bridge = new IpcBridge();

// Handle events
bridge.on('ready', ({ socket }) => {
  console.log('Bridge ready on socket:', socket);
});

bridge.on('connect', ({ id, pid }) => {
  console.log('Client connected:', id, 'PID:', pid);
});

bridge.on('message', ({ id, msg }) => {
  console.log('Received from client:', id, Buffer.from(msg, 'base64').toString());
});

// Start the bridge
await bridge.start();

// Send messages
bridge.send({
  id: 'client-id',
  msg: Buffer.from('Hello!').toString('base64')
});

// Clean up
await bridge.stop();

Command Line Usage

# Start with generated socket path
ipc-json-bridge

# Specify custom socket path
ipc-json-bridge /path/to/socket

# Windows named pipe
ipc-json-bridge my-pipe-name

# Or connect to an existing socket
ipc-json-bridge --client /path/to/socket

# For convenience we also provide a --server flag,
# which is equivalent to the default behavior
ipc-json-bridge --server /path/to/socket

Protocol Specification

If you prefer to implement your own SDK, the bridge uses a simple JSON-based protocol for communication. The following sections provide details on the message format and protocol flow.

Message Format

interface Message {
  // Core fields
  id?: string;          // Client identifier
  msg?: string;         // Base64-encoded payload
  disconnect?: boolean; // Request connection termination
  
  // Status fields
  action?: 'connect' | 'disconnect'; // Connection status
  pid?: number;                      // Process ID (Unix only)
  
  // System fields
  socket?: string;      // Socket path
  version?: number;     // Protocol version
  
  // Error handling
  error?: string;       // Error description
  details?: string;     // Error details
}

Protocol Flow

  1. Initialization

    {"socket": "/path/to/socket", "version": 1}
  2. Client Connection

    {"id": "uuid", "action": "connect", "pid": 1234}
  3. Message Exchange

    // Outgoing
    {"id": "uuid", "msg": "base64-encoded-data"}
       
    // Optional disconnect
    {"id": "uuid", "msg": "base64-encoded-data", "disconnect": true}
  4. Client Disconnection

    {"id": "uuid", "action": "disconnect"}

Error Handling

{"error": "Error description", "details": "Detailed error information"}

Example Communication Flow

# Bridge initialization
> {"socket":"/tmp/ipc_socket_uuid", "version": 1}

# Client connects
> {"id":"client-uuid","action":"connect","pid":1234}

# Send message
< {"id":"client-uuid","msg":"SGVsbG8gV29ybGQh"}

# Receive response
> {"id":"client-uuid","msg":"UmVzcG9uc2UK"}

# Disconnect client
< {"id":"client-uuid","msg":"R29vZGJ5ZQ==","disconnect":true}

# Client disconnected
> {"id":"client-uuid","action":"disconnect"}

Platform-Specific Considerations

Unix

  • Socket files persist until deleted
  • PID tracking available
  • Standard file permissions apply

Darwin

  • Socket files persist until deleted
  • PID tracking not available
  • Standard file permissions apply

Windows

  • Named pipes follow \\.\pipe\<name> convention
  • PID tracking not available
  • Different permission model

License

This project is licensed under the MIT License.

About

MIT

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

What you can do

| Permissions | Conditions | Limitations | |-----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------| | 🟢 Commercial useThe licensed material and derivatives may be used for commercial purposes. | 🔵 License and copyright noticeA copy of the license and copyright notice must be included with the licensed material. | 🔴 LiabilityThis license includes a limitation of liability. | | 🟢 DistributionThe licensed material may be distributed. | | 🔴 WarrantyThis license explicitly states that it does NOT provide any warranty. | | 🟢 ModificationThe licensed material may be modified. | | | | 🟢 Private useThe licensed material may be used and modified in private. | | |

Information provided by https://choosealicense.com/licenses/mit/, this is not legal advice.