@nanoforge-dev/network-client
v1.1.0
Published
NanoForge Engine - Network Client
Downloads
69
Readme
About
@nanoforge-dev/network-client is a network lib with tcp and udp support for client-side usage.
Installation
Node.js 24.11.0 or newer is required.
npm install @nanoforge-dev/network-client
yarn add @nanoforge-dev/network-client
pnpm add @nanoforge-dev/network-client
bun add @nanoforge-dev/network-clientExample usage
Initilize the library in your main file.
import { type IRunClientOptions } from "@nanoforge-dev/common";
import { NanoforgeFactory } from "@nanoforge-dev/core";
import { NetworkClientLibrary } from "@nanoforge-dev/network-client";
export async function main(options: IRunClientOptions) {
const app = NanoforgeFactory.createClient();
const network = new NetworkClientLibrary();
app.useNetwork(network);
await app.init(options);
await app.run();
}Use to receive packets
export function myReceiveSystem(registry: Registry, ctx: Context) {
const network = ctx.libs.getNetwork<NetworkClientLibrary>();
network.tcp.getReceivedPackets().forEach((packet) => {
const data = JSON.parse(new TextDecoder().decode(packet));
// Do something with the data
});
}Use to send packets
export function mySendSystem(registry: Registry, ctx: Context) {
const network = ctx.libs.getNetwork<NetworkClientLibrary>();
// Do something to get a data
const packet = new TextEncoder().encode(JSON.stringify(data));
network.tcp.sendPacket(packet);
}Links
Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
documentation.
See the contribution guide if you'd like to submit a PR.
Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to ask questions in discussions.
