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
hostHost to listen onportPort to listen on
Return value
connect_tcp()
Open a connection to the given host on a given port.
Usage
local conn = vlc.net.connect_tcp(host, port)
Parameters
hostHost to connect toportPort to connect to
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
connopen connectiondataString containing data to send- Optional
lengthLength of data fromdatato send
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
connopen connection- Optional
maxlengthInteger value specifying maximum number of bytes to read from connection
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
connconnection to be closed
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
fd-eventsTable with{ fd: events }entries, where:fdis a file descriptor to polleventsis a number that indicates the events you want to poll for (POLLIN,POLLOUT,POLLPRI)
Return value
Integer value; positive or zero on success, negative on failure
read()
Read data from a file.
NOTE: Not available on Windows.
Parameters
fdInteger: File descriptor- Optional
maxlengthInteger specifying maximum length of data to be read; defaults to 1 byte
Return value
String containing the read data or nil
write()
Write data to a file.
NOTE: Not available on Windows.
Parameters
fdFile descriptorbufferString containing the data to be written- Optional
lengthNumber of bytes ofbufferto be written; defaults to length ofbuffer
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
pathValid path
Return value
Table with the following fields:
.typeOne of “file”, “dir”, “character device”, “block device”, “fifo”, “symbolic link”, “socket”, “unknown”.modeProtection mode.uidUser Identifier of owner.gidGroup Identifier of owner.sizeTotal file size, in bytes.access_timeTime of last access.modification_timeTime of last modification.creation_timeTime of creation
opendir()
List a directory’s contents
Parameters
pathString containing path to directory
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
POLLINThere is data to readPOLLPRIThere is some exceptional condition on the file descriptorPOLLOUTWriting is now possiblePOLLERRError condition (only returned in revents)POLLHUPHang up (only returned in revents)POLLNVALInvalid request: fd not open (only returned in revents)