5:1 ˆÈÉ „ �ˆ?Æ¿Ä?÷ LuaSocket: UDP support

LuaSocket
Network support for the Lua language

home · download · installation · introduction · reference


UDP

socket.udp()

Creates and returns an unconnected IPv4 UDP object. Unconnected objects support the sendto, receive, receivefrom, getoption, getsockname, setoption, settimeout, setpeername, setsockname, and close. The setpeername is used to connect the object.

In case of success, a new unconnected UDP object returned. In case of error, nil is returned, followed by an error message.

socket.udp6()

Creates and returns an unconnected IPv6 UDP object. Unconnected objects support the sendto, receive, receivefrom, getoption, getsockname, setoption, settimeout, setpeername, setsockname, and close. The setpeername is used to connect the object.

In case of success, a new unconnected UDP object returned. In case of error, nil is returned, followed by an error message.

Note: The TCP object returned will have the option "ipv6-v6only" set to true.

connected:close()
unconnected:close()

Closes a UDP object. The internal socket used by the object is closed and the local address to which the object was bound is made available to other applications. No further operations (except for further calls to the close method) are allowed on a closed socket.

Note: It is important to close all used sockets once they are not needed, since, in many systems, each socket uses a file descriptor, which are limited system resources. Garbage-collected objects are automatically closed before destruction, though.