Posted 09 May 2018 - 07:33 PM
I decided to make an internet system for my OS and CraftOS. I made the browser (so far uses the DNS to resolve a domain to an ID) and the DNS. The DNS nicely receives the request for the ID, but doesn't send it, even though both the domain and ID are present in its ids table.
(BTW, I know that the Rednet API has a small DNS inside of it. Don't mention it. Please.)
Browser (or is it so far?):
DNS:
(BTW, I know that the Rednet API has a small DNS inside of it. Don't mention it. Please.)
Browser (or is it so far?):
rednet.open("top")
print("DNS ID:")
local dns = tonumber(read())
print("URL:")
local url = read()
rednet.send(dns, url, "REQUEST_ID")
local event, id, msg, protocol = os.pullEvent("rednet_message")
if protocol == "ID" then
print(url.." resolved to "..msg)
end
DNS:
local tArgs = {...}
if #tArgs < 1 then
error("dns <wireless modem side>", 0)
end
local mSide = tArgs[1]
local modem = nil
if peripheral.getType(mSide) ~= "modem" then
error("No modem detected on the "..mSide.." side of the computer...", 0)
else
modem = peripheral.wrap(mSide)
if not modem.isWireless() then
error("The modem on the "..mSide.." side of the computer is wired!", 0)
end
end
local ids = {
["cabbage.com"] = 3
}
rednet.open(mSide)
while true do
local event, id, msg, protocol = os.pullEvent("rednet_message")
if protocol == "REQUEST_ID" then
print("Computer #"..id.." requested ID of "..msg)
for i=1, #ids do
if ids[msg] then
rednet.send(id, ids[msg], "ID")
print("Replied with "..ids[msg].." to computer #"..id)
end
end
end
end