1
Instalación en NPM
A diferencia de los Websockets donde necesitas instalar librerías pesadas como `socket.io`, aquí instalas el motor de Protocolo Orzatty que trae el binario de Rust incrustado. ¡Cero dependencias extra!
Ejecuta esto en tu terminal donde tengas tu `package.json`:
npm install @orzattyholding/po
💡 Para que lo entiendas súper fácil: Es como ir a la tienda y comprar el "Motor Orzatty" ya ensamblado. No tienes que armar nada, solo lo metes en tu bolsa (tu proyecto) y ya puedes usarlo.
2
Escribir o Escuchar Mensajes (El Servidor Node)
Vamos a usar el clásico `async/await` de JavaScript para esperar los mensajes. El motor C++ por debajo se encarga de que tu Node.js no se trabe (Event Loop intacto).
Abre tu archivo `server.js` y escribe esto:
const { PoClient } = require('@orzattyholding/po');
async function iniciarServidor() {
// 1. Abrimos el puerto 5547
const server = await PoClient.bind(5547);
console.log("¡Orzatty Server Node.js Listo!");
// 2. Nos quedamos escuchando con un ciclo
while (true) {
const datos_cifrados_ya_abiertos = await server.recv();
if (!datos_cifrados_ya_abiertos) break; // Si se cierra, salimos
console.log("Secreto recibido: " + datos_cifrados_ya_abiertos.toString());
}
}
iniciarServidor();
💡 Para que lo entiendas súper fácil: Imagina que tienes a un secretario mágico (`await server.recv()`). Le dices "avísame cuando llegue una carta sellada". Tú te pones a hacer otras cosas, y cuando la carta llega, el secretario abre el sello mágico y te la lee en voz alta. Si el secretario te dice que no hay más cartas (`!datos`), pides apagar las luces (`break`).
3
Conectarse desde Otro Archivo Node.js
Crear una conexión es igual de fácil. Recuerda que con PO, la seguridad E2EE no necesita certificados TLS comprados a Amazon o GoDaddy. ¡Es seguridad matemática embebida!
const { PoClient } = require('@orzattyholding/po');
async function conectarYEnviar() {
// 1. Apuntamos a nuestro amigo en su casa (puerto 5547)
const client = await PoClient.connect("127.0.0.1:5547");
// 2. Transmutamos el texto a Binario (Buffer) y lo enviamos
let paquete = Buffer.from("Hola servidor de Orzatty");
await client.send(paquete);
}
conectarYEnviar();
💡 Para que lo entiendas súper fácil: JavaScript usa "Palabras" (Strings). Las redes usan "Electricidad" (Bytes/Buffer). Un `Buffer.from()` es como tomar tus palabras en un papel y convertirlas en aviones de papel antes de lanzarlas por el aire (`client.send()`).
4
sendBatch (Explotando la Aceleración de Hardware)
Si tienes una app como WhatsApp o un juego en tiempo real, no mandes paquete por paquete. Agrúpalos en un `[]` Array de Buffers y dispara `sendBatch`.
const mis_100_mensajes = [];
for(let i=0; i < 100; i++){
mis_100_mensajes.push(Buffer.from("posición X Y"));
}
// Esto es 5 veces más rápido!
await client.sendBatch(mis_100_mensajes);
1
Installation with NPM
Unlike Websockets where you install heavy libraries like `socket.io`, here you install the Orzatty Protocol engine which brings the Rust binary embedded. Zero extra dependencies!
Run this in your terminal where you have your `package.json`:
npm install @orzattyholding/po
💡 To make it super easy to understand: It's like going to the store and buying the already assembled "Orzatty Engine". You don't have to build anything, just put it in your bag (your project) and you can use it.
2
Start Listening (The Node Server)
We will use classic JavaScript `async/await` to wait for messages. The C++ engine underneath ensures your Node.js doesn't freeze (Event Loop intact).
Open your `server.js` file and write this:
const { PoClient } = require('@orzattyholding/po');
async function startServer() {
// 1. We open port 5547
const server = await PoClient.bind(5547);
console.log("Orzatty Node.js Server Ready!");
// 2. We stay listening in a loop
while (true) {
const decrypted_data = await server.recv();
if (!decrypted_data) break; // Disconnected
console.log("Received Secret: " + decrypted_data.toString());
}
}
startServer();
💡 To make it super easy to understand: Imagine you have a magical secretary (`await server.recv()`). You tell him "let me know when a sealed letter arrives". You go do other things, and when the letter arrives, the secretary opens the magic seal and reads it out loud. If he says there are no more coming (`!data`), you close down (`break`).
3
Connecting from Another File
Creating a connection is just as easy. Remember that with PO, E2EE security does not need TLS certs bought from Amazon or GoDaddy. It's built-in mathematical security!
const { PoClient } = require('@orzattyholding/po');
async function connectAndSend() {
// 1. Point to our friend's house (port 5547)
const client = await PoClient.connect("127.0.0.1:5547");
// 2. Transmute text to Binary (Buffer) and send it
let packet = Buffer.from("Hello Orzatty Server");
await client.send(packet);
}
connectAndSend();
💡 To make it super easy to understand: JavaScript uses Words (Strings). Networks use Electricity (Bytes/Buffer). A `Buffer.from()` is like taking your words on paper and folding them into paper airplanes before tossing them in the air (`client.send()`).
4
sendBatch (Hardware Acceleration)
If you have a realtime app like WhatsApp, don't send packet by packet. Group them in an Array of Buffers and fire `sendBatch`.
const my_100_msgs = [];
for(let i=0; i < 100; i++){
my_100_msgs.push(Buffer.from("X Y Position"));
}
// This is 5 times faster!
await client.sendBatch(my_100_msgs);