Skip to content

Search documentation

Enter at least two characters.

    UdpSocket

    SDK 0.1.0-preview.2 · ExperimentalDownload & release notes ↗

    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.

    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 = true

    Expected result: Sends one local datagram and displays its bytes and sender. UDP delivery is not guaranteed outside this demonstration.

    Whether the socket is open.

    Type: boolean. Read-only.

    Actual local address and port.

    Type: NetworkEndpoint. Read-only.

    Yields for one datagram and returns its bytes and sender. Close the socket to cancel a pending receive.

    ReceiveFromAsync() -> UdpDatagram

    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) -> (),
    }

    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.