NetworkService
Capability-gated TCP and UDP networking with bounded asynchronous operations.
Advanced app/host integration API. Useful for lower-level work; ordinary app authors can start with the app-building path. This is public API, not permission to access private toolkit objects.
Required setup
Section titled “Required setup”network.raw plus network.client for outgoing connections/sends and network.server for listening/receiving. Use HTTP services instead if that is your protocol.
The host is the program running your Luau code: normally the SDK’s native runner. Its provider/adapter implements an optional service. You do not need to write one to use a service already supplied by the SDK. Capabilities explains the manifest and remaining platform limits.
Example
Section titled “Example”Advanced raw networking. Calls that wait for I/O belong in task.spawn/task.defer; normal HTTP apps can use HttpService instead.
Where to put it: replace Src/Main.luau in a project created with this SDK. This is the complete entry file.
Project setup: add network.raw, network.client, network.server to Capabilities in lui.json. See the capability guide.
local Window = Instance.new("Window", { Title = "LUI example", Size = UDim2.fromOffset(560, 280),})local Status = Instance.new("TextLabel", { Parent = Window, Text = "Ready", Position = UDim2.fromOffset(16, 170), Size = UDim2.new(1, -32, 0, 72),})local Network = app:GetService("NetworkService")local Listener = Network:ListenTcp({Address = "loopback", Port = 0})task.spawn(function() local Peer = Listener:AcceptAsync() local Bytes = Peer:ReadExactAsync(4) Peer:WriteAsync(Bytes) Peer:Close() Listener:Close()end)task.spawn(function() local Peer = Network:ConnectTcp({Address = "127.0.0.1", Port = Listener.Port}) Peer:WriteAsync("ping") local Reply = Peer:ReadExactAsync(4) Status.Text = buffer.tostring(Reply) Peer:Close()end)Window.Destroying:Connect(function() Listener:Close() end)Window.Visible = trueExpected result: A local TCP client sends four bytes and receives the echo. The fixed four-byte length is this example’s framing rule, not a TCP message boundary.
Behavior and limits
Section titled “Behavior and limits”- Raw sockets are an advanced choice. Use HttpService or JsonClient for an HTTP/JSON endpoint.
- TCP is a byte stream; one write need not match one read. Define message framing in your application protocol.
Methods
Section titled “Methods”ListenTcp
Section titled “ListenTcp”Binds a TCP listener immediately. Requires network.raw and network.server. Port 0 asks the OS to choose a free port when policy allows it.
ListenTcp(Options: NetworkListenOptions) -> TcpListenerConnectTcp
Section titled “ConnectTcp”Connects in a yielding task and returns a TcpConnection. Requires network.raw and network.client; host address/port policy still applies.
ConnectTcp(Options: NetworkConnectOptions) -> TcpConnectionBindUdp
Section titled “BindUdp”Binds a UDP socket. Requires network.raw and the client/server grants for the operations your app performs.
BindUdp(Options: UdpBindOptions) -> UdpSocketFull type declaration — for type checking and deeper reference
The declaration is generated from the SDK. Self is supplied by a colon call; read means the field cannot be assigned. See how to read this reference.
export type NetworkService = { read ListenTcp: (Self: NetworkService, Options: NetworkListenOptions) -> TcpListener, read ConnectTcp: (Self: NetworkService, Options: NetworkConnectOptions) -> TcpConnection, read BindUdp: (Self: NetworkService, Options: UdpBindOptions) -> UdpSocket,}Availability and deeper reading
Section titled “Availability and deeper reading”See platform limits before relying on host-specific behavior. The framework design specification and reflection/type sources are deeper engineering references, not extra setup required to build an app.