Network utilities, many of which are analogous to net utilities found in Linux.
NOTE: File descriptors are passed to (and returned by) functions as non-negative integer values.

Availability

Script Types
Extension, Interface

TCP Connections

Methods to create, manage and listen for TCP connections.

listen_tcp()

Listen to TCP connections; creates Net Listen Object.

Usage

local listener = vlc.net.listen_tcp(host, port)
while true do
	local conn = listener:accept()
	if conn >= 0 do
		net.send(conn, "blabla")
		net.close(conn)
	end
end

Parameters

Return value

A listen object


connect_tcp()

Open a connection to the given host on a given port.

Usage

local conn = vlc.net.connect_tcp(host, port)

Parameters

Return value

File descriptor to accepted connection or -1 on failure


send()

Send data on an open TCP connection

Usage

local conn = vlc.net.connect_tcp(host, port)
...
vlc.net.send(conn, data[, length])

Parameters

Return value

Integer value indicating the number of bytes sent on success; -1 on failure


recv()

Receive data from connection.

Usage

vlc.net.recv(conn[, maxlength])

Parameters

Return value

String containing the data read from the TCP socket or nil if error occurred


close()

Close an open connection.

Usage

vlc.net.close(conn)

Parameters


Other Methods

Some extra functions, most of which are non-network or deprecated.

poll()

Polls file descriptor(s); similar to poll.
Parameter is modified to include revents (returned events) which indicate what type of I/O is available for the file descriptor.
All events refer to poll event flags.

Parameters

Return value

Integer value; positive or zero on success, negative on failure


read()

Read data from a file.
NOTE: Not available on Windows.

Parameters

Return value

String containing the read data or nil


write()

Write data to a file.
NOTE: Not available on Windows.

Parameters

Return value

Integer indicating the number of bytes written to fd or -1 if write failed


url_parse()

Alias for strings.url_parse().
Deprecated since 3.0.0, kept for backwards compatibility.


stat()

Similar to stat() in POSIX C.

Parameters

Return value

Table with the following fields:


opendir()

List a directory’s contents

Parameters

Return value

List of file and/or folder names


Listen Object

The object returned by listen_tcp(); houses the following methods.

listen:accept()

Accept a TCP connection; similar to accept.
This is a blocking call, for non-blocking use listen:fds().

Return value

File descriptor for the accepted socket (non-negative integer)


listen:fds()

Get file descriptors that can be polled before use.

Return value

List of available socket file descriptors


Poll Event Flags