rednet.lookup

From ComputerCraft Wiki
Revision as of 06:33, 6 June 2014 by Bomb Bloke (Talk | contribs) (Navigation template)

(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).

Lookups are broadcasted with a specified protocol of "dns". Replies are sent back to the sender's ID number with the same protocol.

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


Grid disk.png Rednet API Functions
rednet.open - rednet.close - rednet.send - rednet.broadcast - rednet.receive - rednet.isOpen - rednet.host - rednet.unhost - rednet.lookup