rednet.lookup

From ComputerCraft Wiki
Revision as of 05:52, 29 March 2014 by Bomb Bloke (Talk | contribs) (Created page with "{{lowercase}} {{Function |name=rednet.lookup |args={{type|string}} protocol, [<nowiki></nowiki>{{type|string}} hostname] |returns={{type|number}} ID1, {{type|number}} ID2, ......")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Grid Redstone.png  Function rednet.lookup
Introduced by ComputerCraft 1.6, searches the local rednet network for systems "hosting" the desired protocol and returns any computer IDs that respond as "registered" against it. If a hostname is specified, only one ID will be returned (assuming an exact match is found).

See also: rednet.host(), rednet.unhost()
Syntax rednet.lookup(string protocol, [string hostname])
Returns number ID1, number ID2, ...
Part of ComputerCraft
API rednet

Examples

Grid paper.png  Example
Attempts to determine the ID of a remote system that has registered itself as using the protocol "futonFolderComs" under the hostname "futonFolderServer".
Code
rednet.open("top")

local futonServerID = rednet.lookup("futonFolderComs","futonFolderServer")

if futonServerID then
	print("Found the server on channel "..futonServerID.."!")
else
	print("Failed to locate the futon server.")
end



Grid paper.png  Example
Attempts to determine the IDs of all remote systems that have registered themselves as using the protocol "futonFolderComs".
Code
rednet.open("top")

local futonServerID = {rednet.lookup("futonFolderComs")}

for i=1,#futonServerID do
	print("Found a server on channel "..futonServerID[i].."!")
end