requestfrom()
- Works exactly as the method, except it passes address and port as extra parameters to a callback.
Edit
Parameter | Type | Required | Description |
---|---|---|---|
handle | int | + | Connection handle |
callback | string | + | Plugin script file that will be called with received data |
user_data | string | – | Any data which will be passed to callback |
size | int | – | Maximum size of the datagram to be retrieved. If omitted, the maximum datagram size is used (which is currently limited by the implementation to 8192 bytes). |
Edit
Nothing
Edit
Parameter | Type | Description |
---|---|---|
event | string | |
data.handle | int | Connection handle |
data.user_data | string | User data passed to request() call |
data.datagram | string | Received datagram |
data.address | string | Sender address |
data.port | string | Sender port |
Edit
local params = ...
local network = require("network")
if params.event == "requestfrom" then
network.sendto(
params.data.handle,
params.data.user_data .. params.data.datagram,
params.data.address,
params.data.port)
return
end
local handle = network.udp();
network.setsockname(handle, "*", "8021")
network.sendto(handle, "Is there anyone?", "192.168.1.255", "8021")
network.requestfrom(handle, "this_script_name", "Hi, ")