Issues with internet system
Windows10User 09 May 2018
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
SquidDev 09 May 2018
At a guess, the problematic line is for i=1, #ids do. The length of a table only includes the array part, so in this particular case #ids is 0. Consequently, the loop is body never executed and so nothing is sent. You can just delete that loop, as the counter isn't actually used.
Windows10User 09 May 2018
SquidDev, on 09 May 2018 - 06:48 PM, said:
At a guess, the problematic line is for i=1, #ids do. The length of a table only includes the array part, so in this particular case #ids is 0. Consequently, the loop is body never executed and so nothing is sent. You can just delete that loop, as the counter isn't actually used.
So what am I supposed to do?
EDIT: Look, look, removing the for fixes it! Now I just need to try with multiple domains.
EDIT 2: It works!!! Thanks 4 saving my life, Squid.
Edited by Windows10User, 09 May 2018 - 06:57 PM.
Dave-ee Jones 10 May 2018
I would suggest using the modem API and doing your own protocols and DNS via tables. Rednet has a few performance issues and isn't very secure (though, you don't really need the security at this stage). You just have a bit more control.
You can do simple things like this:
You can do simple things like this:
local m_TOP = peripheral.wrap("top") m_TOP.open(os.getComputerID()) m_TOP.transmit(65535,65533,{ PROTOCOL = "BROADCAST", DATA = { "jack", "jill" }, MY_ID = os.getComputerID() })
Marc1miner 10 May 2018
Dave-ee Jones, on 10 May 2018 - 12:23 AM, said:
I would suggest using the modem API and doing your own protocols and DNS via tables. Rednet has a few performance issues and isn't very secure (though, you don't really need the security at this stage). You just have a bit more control.
You can do simple things like this:
You can do simple things like this:
local m_TOP = peripheral.wrap("top") m_TOP.open(os.getComputerID()) m_TOP.transmit(65535,65533,{ PROTOCOL = "BROADCAST", DATA = { "jack", "jill" }, MY_ID = os.getComputerID() })
If you do decide to follow this instruction and write your own protocol, you need to write a receiving modem on the same transmit id. Otherwise you'll be sending but not receiving.
Windows10User 10 May 2018
I think the modem API is too difficult to learn and use in general.
Edited by Windows10User, 10 May 2018 - 12:31 PM.
Edited by Windows10User, 10 May 2018 - 12:31 PM.