net
http_get
http_get(url: string, headers: string, fn: (string))
Performs a GET request to the given url.
Parameters
Name | Type | Description |
---|---|---|
url |
string | Request URL |
headers |
string | Headers. Empty string will not add any headers to the request |
fn |
function(string) | Result callback |
Usage
net.http_get('https://pastebin.com/raw/FT1aRqq8', 'Accept: */*', function(response)
print(response);
end);
http_post
http_post(url: string, headers: string, body: string, fn: (string))
Performs a POST request to the given url.
Parameters
Name | Type | Description |
---|---|---|
url |
string | Request URL |
headers |
string | Headers. Empty string will not add any headers to the request |
body |
string | Request body |
fn |
function(string) | Result callback |
Usage
net.http_post(
'https://reqbin.com/echo/post/json',
'Content-Type: application/json',
'{"id": 12345}',
function(response)
print(response);
end
);
listen
listen(id: string, on_ready: ())
Allows the client to receive messages sent to the room.
Note
Make sure that id
is as unique as possible. If your room ID is known to someone else, they will be able to sniff and spoof data sent within your room's context.
Parameters
Name | Type | Description |
---|---|---|
id |
string | Room ID |
Usage
net.listen('my-script', function ()
print('Ready to send and receive!');
end);
broadcast
broadcast(id: string, data: table)
Broadcasts data to the room.
Parameters
Name | Type | Description |
---|---|---|
id |
string | Room ID |
data |
table | Any data. Note that it will be encoded into JSON before sending out |
Usage
-- user A
net.broadcast('my-script', {
a = 1,
b = 5
});
-- user B
function on_net_data(id, from, data)
-- data = { a = 1, b = 5 }
end