Zubox is a Node.js package for creating and managing TCP clients and servers.
You can install Zubox via npm:
npm install zubox
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);
});
-
new Host(port: number)
: Creates a new server instance listening on the specified port.
-
listen(callback: Function)
: Starts listening for incoming connections. The callback function is invoked when data is received.
-
new Client(options: { host: string, port: number })
: Creates a new client instance with the specified host and port.
-
connect(data: any)
: Connects the client to the server with optional data. -
sync(action: string)
: Synchronizes data with the server for the specified action.