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';
const myServer = new Host(4051);
const myClient = new Client({ host: 'localhost', port: 4051 });
myServer.listen((data) => {
if (data().author !== "host") {
return;
}
console.log(data());
return data().data[data().data.length - 1];
});
myClient.connect({ author: "host" });
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!