Module system.network

The network module implements functions for making and hosting connections with local and Internet-connected computers, as well as managing the network stack configuration.

Index

Function

checkURI()

connect()

Creates a new connection to a remote server.

control()

delete()

Connects to an HTTP(S) server, sends a DELETE request and waits for a response.

events()

get()

Connects to an HTTP(S) server, sends a GET request and waits for a response.

getData()

Connects to an HTTP(S) server, sends a GET request, waits for a response, and returns the data received after closing the connection.

head()

Connects to an HTTP(S) server, sends a HEAD request and waits for a response.

ipconfig()

listen()

options()

Connects to an HTTP(S) server, sends an OPTIONS request and waits for a response.

parseURI()

Parses a URI into its components.

post()

Connects to an HTTP(S) server, sends a POST request and waits for a response.

put()

Connects to an HTTP(S) server, sends a PUT request and waits for a response.

unlisten()

urlEncode()

Class

Handle

HTTPHandle

API Reference

system.network.parseURI(uri: string): (result: table)

Parses a URI into its components.

Parameters:

uri (string) – The URI to parse

Returns:

result (table) – The components of the URI

system.network.connect(options: string | table): (result: system.network.Handle)

Creates a new connection to a remote server.

Parameters:

options (string | table) – The URI to connect with, or a table of options (see the connect syscall docs for more information)

Returns:

result (system.network.Handle) – A handle to the connection

system.network.get(options: string | table): (The: system.network.Handle | nil, An: string | nil)

Connects to an HTTP(S) server, sends a GET request and waits for a response.

Parameters:

options (string | table) – The URL to connect to, or a table of options (see the connect syscall docs for more information)

Returns:
  • The (system.network.Handle | nil) – handle to the response data, or nil if the connection failed

  • An (string | nil) – error describing why the connection failed

system.network.getData(url: string, headers?: table): (data: string | nil, code: string | number)

Connects to an HTTP(S) server, sends a GET request, waits for a response, and returns the data received after closing the connection.

Parameters:
  • url (string) – The URL to connect to

  • headers? (table) – Any headers to send in the request

Returns:
  • data (string | nil) – The response data sent from the server, or nil if the connection failed

  • code (string | number) – The HTTP response code for the response, or an error describing why the connection failed

system.network.head(options: string | table): (The: system.network.Handle | nil, An: string | nil)

Connects to an HTTP(S) server, sends a HEAD request and waits for a response.

Parameters:

options (string | table) – The URL to connect to, or a table of options (see the connect syscall docs for more information)

Returns:
  • The (system.network.Handle | nil) – handle to the response data, or nil if the connection failed

  • An (string | nil) – error describing why the connection failed

system.network.options(options: string | table): (The: system.network.Handle | nil, An: string | nil)

Connects to an HTTP(S) server, sends an OPTIONS request and waits for a response.

Parameters:

options (string | table) – The URL to connect to, or a table of options (see the connect syscall docs for more information)

Returns:
  • The (system.network.Handle | nil) – handle to the response data, or nil if the connection failed

  • An (string | nil) – error describing why the connection failed

system.network.post(options: string | table, data: string): (The: system.network.Handle | nil, An: string | nil)

Connects to an HTTP(S) server, sends a POST request and waits for a response.

Parameters:
  • options (string | table) – The URL to connect to, or a table of options (see the connect syscall docs for more information)

  • data (string) – The data to send to the server

Returns:
  • The (system.network.Handle | nil) – handle to the response data, or nil if the connection failed

  • An (string | nil) – error describing why the connection failed

system.network.put(options: string | table, data: string): (The: system.network.Handle | nil, An: string | nil)

Connects to an HTTP(S) server, sends a PUT request and waits for a response.

Parameters:
  • options (string | table) – The URL to connect to, or a table of options (see the connect syscall docs for more information)

  • data (string) – The data to send to the server

Returns:
  • The (system.network.Handle | nil) – handle to the response data, or nil if the connection failed

  • An (string | nil) – error describing why the connection failed

system.network.delete(options: string | table, data: string): (The: system.network.Handle | nil, An: string | nil)

Connects to an HTTP(S) server, sends a DELETE request and waits for a response.

Parameters:
  • options (string | table) – The URL to connect to, or a table of options (see the connect syscall docs for more information)

  • data (string) – The data to send to the server

Returns:
  • The (system.network.Handle | nil) – handle to the response data, or nil if the connection failed

  • An (string | nil) – error describing why the connection failed

system.network.listen(uri: any): unknown
system.network.unlisten(uri: any): unknown
system.network.ipconfig(device: any, info: any): unknown
system.network.control(ip: any, type: any, err: any): unknown
system.network.events(state: any): unknown
system.network.checkURI(uri: any): unknown
system.network.urlEncode(str: any)
class system.network.Handle: file*
status(self: system.network.Handle): (
    status: "closed" | "connecting" | "error" | "open" | "ready",
    error: string | nil
)

Returns the status of the handle.

Returns:
  • status ("closed" | "connecting" | "error" | "open" | "ready") – The status of the handle

  • error (string | nil) – If in error state, an error message associated with the status

close(self: file*): (
    suc?: true,
    exitcode?: "exit" | "signal",
    code?: integer
)

Close file.

View documents

flush(self: file*)

Saves any written data to file.

View documents

lines(self: file*, ...: string | integer | "L" | "a" | "l"...(+1)): fun(): any, ...unknown

View documents

read(self: file*, ...: string | integer | "L" | "a" | "l"...(+1)): (any, ...: any)

Reads the file, according to the given formats, which specify what to read.

View documents

seek(
    self: file*,
    whence?: "cur" | "end" | "set",
    offset?: integer
): (offset: integer, errmsg?: string)

Sets and gets the file position, measured from the beginning of the file.

View documents

setvbuf(self: file*, mode: "full" | "line" | "no", size?: integer)

Sets the buffering mode for an output file.

View documents

write(self: file*, ...: string | number): (file*?, errmsg?: string)

Writes the value of each of its arguments to file.

View documents

class system.network.HTTPHandle: system.network.Handle
responseHeaders(self: system.network.HTTPHandle): (headers: {[string]: string} | nil)

Returns the response headers for the request.

Returns:

headers ({[string]: string} | nil) – The headers in the response

responseCode(self: system.network.HTTPHandle): (code: number | nil)

Returns the response code for the request.

Returns:

code (number | nil) – The code from the response