Quick Start
Get PaindaProtocol running and build a "Hello World" chat in under 2 minutes.
Installation
npm install @painda/coreHello World Chat
Create a minimal server and client that exchange a single binary-framed message.
Server
import { PPServer } from '@painda/core';
const server = new PPServer({ port: 3000 });
server.on('connection', (client) => {
client.on('message', (data) => {
console.log('Received:', data);
client.send({ type: 'hello', payload: 'World' });
});
});Client
import { PPClient } from '@painda/core';
const client = new PPClient({ url: 'ws://localhost:3000' });
client.on('open', () => {
client.send({ type: 'greet', payload: 'Hello' });
});
client.on('message', (data) => {
console.log('Server says:', data.payload); // "World"
});Typed Contracts
Register schemas for binary-native serialization with full TypeScript inference. No more JSON overhead.
import {
PPServer,
PPSchemaRegistry,
structSerializer,
} from '@painda/core';
// Define a binary schema for player positions
const registry = new PPSchemaRegistry();
registry.register('player:move', structSerializer(1, [
{ name: 'x', type: 'float32' },
{ name: 'y', type: 'float32' },
{ name: 'z', type: 'float32' },
]));
// Pass the registry to the server
const server = new PPServer({
port: 3000,
mode: 'gaming',
registry,
});
server.on('connection', (client) => {
client.on('message', (msg) => {
if (msg.type === 'player:move') {
const { x, y, z } = msg.payload as { x: number; y: number; z: number };
console.log(`Player moved to ${x}, ${y}, ${z}`);
}
});
// Send a typed binary message (12 bytes instead of ~50+ JSON bytes)
client.send({ type: 'player:move', payload: { x: 1.5, y: 0, z: -3.2 } });
});The schema registry maps player:move to a compact 12-byte struct (3 x float32) instead of a ~50-byte JSON string. Unregistered types fall back to JSON automatically.
Next, explore PP.Chat for rooms and history, or The PP Header for the binary wire format.