UdpSocket
An owned UDP socket with asynchronous datagram receive and send 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.
Example
Section titled “Example”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 Receiver = Network:BindUdp({Address = "loopback", Port = 0, MaxDatagramBytes = 1024})local Sender = Network:BindUdp({Address = "loopback", Port = 0, MaxDatagramBytes = 1024})task.spawn(function() local Packet = Receiver:ReceiveFromAsync() Status.Text = buffer.tostring(Packet.Data) .. " from " .. Packet.RemoteEndpoint.Address Receiver:Close()end)task.spawn(function() Sender:SendToAsync(Receiver.LocalEndpoint, "Hello UDP") Sender:Close()end)Window.Destroying:Connect(function() Receiver:Close(); Sender:Close() end)Window.Visible = trueExpected result: Sends one local datagram and displays its bytes and sender. UDP delivery is not guaranteed outside this demonstration.
Properties
Section titled “Properties”IsOpen
Section titled “IsOpen”Whether the socket is open.
Type: boolean. Read-only.
LocalEndpoint
Section titled “LocalEndpoint”Actual local address and port.
Type: NetworkEndpoint. Read-only.
Methods
Section titled “Methods”ReceiveFromAsync
Section titled “ReceiveFromAsync”Yields for one datagram and returns its bytes and sender. Close the socket to cancel a pending receive.
ReceiveFromAsync() -> UdpDatagramSendToAsync
Section titled “SendToAsync”Yields while sending one string/buffer payload to the supplied endpoint. UDP does not guarantee delivery or ordering.
SendToAsync(Endpoint: NetworkEndpoint, Data: string | buffer) -> ()Closes the socket and cancels pending operations. Repeated close is safe.
Close() -> ()Full 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 UdpSocket = { read IsOpen: boolean, read LocalEndpoint: NetworkEndpoint, read ReceiveFromAsync: (Self: UdpSocket) -> UdpDatagram, read SendToAsync: (Self: UdpSocket, Endpoint: NetworkEndpoint, Data: string | buffer) -> (), read Close: (Self: 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.