zubox

1.0.8 • Public • Published

Zubox

Zubox is a Node.js package for creating and managing TCP clients and servers.

Installation

You can install Zubox via npm:

npm install zubox

Usage

import { Client, Host } from 'zubox';

// Create a server instance
const myServer = new Host(4051);

// Create a client instance
const myClient = new Client({ host: 'localhost', port: 4051 });

// Listen for incoming data on the server
myServer.listen((data) => {
    if (data().author !== "host") {
        return;
    }
    console.log(data());
    return data().data[data().data.length - 1];
});

// Connect the client to the server
myClient.connect({ author: "host" });

// Synchronize data with the server
myClient.sync('pull');
myClient.sync('robot').then((dataa) => {
    console.log("Promise resolved, " + dataa);
});

API

Host

Constructor

  • new Host(port: number): Creates a new server instance listening on the specified port.

Methods

  • listen(callback: Function): Starts listening for incoming connections. The callback function is invoked when data is received.

Client

Constructor

  • new Client(options: { host: string, port: number }): Creates a new client instance with the specified host and port.

Methods

  • connect(data: any): Connects the client to the server with optional data.
  • sync(action: string): Synchronizes data with the server for the specified action.

More coming soon!

Readme

Keywords

none

Package Sidebar

Install

npm i zubox

Weekly Downloads

15

Version

1.0.8

License

ISC

Unpacked Size

5.85 kB

Total Files

6

Last publish

Collaborators

  • renderthegreat