setsockname()
- Binds the UDP socket to a local address. Address can be an IP address or a host name. If address is ‘‘ the system binds to all local interfaces using the constant . If port is , the system chooses an ephemeral port.
- Note: This method can only be called before any datagram is sent through the UDP socket, and only once. Otherwise, the system automatically binds the socket to all local interfaces and chooses an ephemeral port as soon as the first datagram is sent. After the local address is set, either automatically by the system or explicitly by , it cannot be changed.
Edit
Parameter | Type | Required | Description |
---|---|---|---|
handle | int | + | Connection handle |
address | string | – | Address to bind |
port | string | – | Port to bind |
Edit
Nothing
Edit
local network = require("network")
local handle = network.udp();
network.setsockname(handle, "*", "8021")