Jump to content




Issues with internet system

networking wireless lua

5 replies to this topic

#1 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 09 May 2018 - 06: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?):
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


#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 09 May 2018 - 06:48 PM

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.

#3 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 09 May 2018 - 06:53 PM

View PostSquidDev, 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.


#4 Dave-ee Jones

  • Members
  • 456 posts
  • LocationVan Diemen's Land

Posted 10 May 2018 - 12:23 AM

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:
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()
})


#5 Marc1miner

  • Members
  • 8 posts

Posted 10 May 2018 - 06:42 AM

View PostDave-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:
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.

#6 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 10 May 2018 - 12:30 PM

I think the modem API is too difficult to learn and use in general.

Edited by Windows10User, 10 May 2018 - 12:31 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users