Version: 2.1.5

Basics

Quick Start#

Three files are needed to get started:

shared/remotes.ts
import Net from "@rbxts/net";
const Remotes = Net.Definitions.Create({
PrintMessage: Net.Definitions.ClientToServerEvent<[message: string, other: string]>(),
MakeHello: Net.Definitions.ServerAsyncFunction<(message: string) => string>(),
});
export { Remotes };
server/test.server.ts
import { Remotes } from "shared/remotes";
// listen to messages
const PrintMessage = Remotes.Server.Create("PrintMessage");
PrintMessage.Connect((player, message, other) => {
print(`Server recieved message: ${message} from player: ${player} ${other}`);
});
// listen and respond to messages
const MakeHello = Remotes.Server.Create("MakeHello");
MakeHello.SetCallback((player, message) => {
print(`Server got an async message from ${player} containing the message ${message}`);
return `Hello, ${player}! We got your message: ${message}`;
});
client/test.client.ts
import { Remotes } from "shared/remotes";
// send a message to the server
const PrintMessage = Remotes.Client.Get("PrintMessage");
PrintMessage.SendToServer("Hello there!", "other");
// send a message to the server, while listening for a response
const MakeHello = Remotes.Client.Get("MakeHello");
MakeHello.CallServerAsync("Net is cool right??").then((result) => {
print(`Client got a response to the async message from server: ${result}`);
});

And away you go - just get editing the remotes file to add your own definitions!