|  Developer
Updated on November 14, 2021

setpeername()

  • Changes the peer of a UDP socket. This method turns an unconnected UDP socket into a connected UDP socket or vice versa.
  • For connected sockets, outgoing datagrams will be sent to the specified peer, and datagrams received from other peers will be discarded by the OS. Connected UDP sockets must use the and methods instead of and .
  • If address is ‘‘ and the socket is connected, the peer association is removed and the socket becomes an unconnected again. In that case, the port argument is ignored.
  • Note: Since the address of the peer does not have to be passed to and from the OS, the use of connected UDP sockets is recommended when the same peer is used for several transmissions.
Edit
Parameter Type Required Description
handle int + Connection handle
address string + IP address or a host name to connect
port string Port to connect
Edit
Nothing
Edit
				
					local network = require("network")
local handle = network.udp();
network.setpeername(handle, "192.168.1.100", "8021")