title | project |
---|---|
Network Module |
vlc-lua-docs |
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.
Script Types |
---|
Extension, Interface |
Methods to create, manage and listen for TCP connections.
Listen to TCP connections; creates Net Listen Object.
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
host
Host to listen onport
Port to listen on
Open a connection to the given host on a given port.
local conn = vlc.net.connect_tcp(host, port)
host
Host to connect toport
Port to connect to
File descriptor to accepted connection or -1
on failure
Send data on an open TCP connection
local conn = vlc.net.connect_tcp(host, port)
...
vlc.net.send(conn, data[, length])
conn
open connectiondata
String containing data to send- Optional
length
Length of data fromdata
to send
Integer value indicating the number of bytes sent on success; -1
on failure
Receive data from connection.
vlc.net.recv(conn[, maxlength])
conn
open connection- Optional
maxlength
Integer value specifying maximum number of bytes to read from connection
String containing the data read from the TCP socket or nil
if error occurred
Close an open connection.
vlc.net.close(conn)
conn
connection to be closed
Some extra functions, most of which are non-network or deprecated.
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.
fd-events
Table with{ fd: events }
entries, where:fd
is a file descriptor to pollevents
is a number that indicates the events you want to poll for (POLLIN
,POLLOUT
,POLLPRI
)
Integer value; positive or zero on success, negative on failure
Read data from a file.
NOTE: Not available on Windows.
fd
Integer: File descriptor- Optional
maxlength
Integer specifying maximum length of data to be read; defaults to 1 byte
String containing the read data or nil
Write data to a file.
NOTE: Not available on Windows.
fd
File descriptorbuffer
String containing the data to be written- Optional
length
Number of bytes ofbuffer
to be written; defaults to length ofbuffer
Integer indicating the number of bytes written to fd
or -1
if write failed
Alias for strings.url_parse().
Deprecated since 3.0.0, kept for backwards compatibility.
Similar to stat() in POSIX C.
path
Valid path
Table with the following fields:
.type
One of "file", "dir", "character device", "block device", "fifo", "symbolic link", "socket", "unknown".mode
Protection mode.uid
User Identifier of owner.gid
Group Identifier of owner.size
Total file size, in bytes.access_time
Time of last access.modification_time
Time of last modification.creation_time
Time of creation
List a directory's contents
path
String containing path to directory
List of file and/or folder names
The object returned by listen_tcp(); houses the following methods.
Accept a TCP connection; similar to accept.
This is a blocking call, for non-blocking use listen:fds().
File descriptor for the accepted socket (non-negative integer)
Get file descriptors that can be polled before use.
List of available socket file descriptors
POLLIN
There is data to readPOLLPRI
There is some exceptional condition on the file descriptorPOLLOUT
Writing is now possiblePOLLERR
Error condition (only returned in revents)POLLHUP
Hang up (only returned in revents)POLLNVAL
Invalid request: fd not open (only returned in revents)