I'm trying to play around with basic network messages and the like (i.e. tell it the port to broadcast on, the message, and the strength desired), and so I created a counterpart listening program to open ports 1-20 and report whether they're functional or non-functional, and then it moves on to waiting for the message. Issue is, when I open the ports up, only ports 20, 10, and 1 actually report being functional, the others all seem to be closed, any ideas?
Broadcast program:
local component = require("component")
local computer = require("computer")
if not component.isAvailable("modem") then
io.stderr:write("A modem is required to use this program, preferably from a wireless network card.")
return
end
if not component.isAvailable("access_point") then
io.stderr:write("An access point is required to use this program. It allows for great wireless transmissions")
return
end
local ap = component.access_point
local m = component.modem
if not m.isWireless() then
print("Sorry, this program only really does anything useful if you have a wireless network card installed")
return
end
print("Please input on which port you would like to broadcast (number): ")
local portstr = io.read()
print("Now, please input the message you would like to send (string): ")
local msg = io.read()
print("Lastly, how far would you like this broadcast to go? (number): ")
local strrange = io.read()
print("Reading input, preparing message...")
local portnum = tonumber(portstr)
print("Message prepared, setting desired broadcast range...")
local range = tonumber(strrange)
m.setStrength(range)
ap.setStrength(range)
print("Range set to: " .. range)
print("Input read, checking port status...")
if m.isOpen(portnum) then
print("Port is opened, proceeding with broadcast...")
if m.broadcast(portnum, msg) then
print("Message successfully sent!")
return
else
print("Message not sent! Unknown reason!")
return
end
else
m.open(portnum)
print("Port has been manually opened, proceeding with broadcast...")
if m.broadcast(portnum, msg) then
print("Message successfully sent!")
return
else
print("Message not sent! Unknown reason!")
return
end
end
Listening program:
local component = require("component")
local event = require("event")
if not component.isAvailable("access_point") then
print("Access Point should be available to assist this program...")
return
end
if not component.isAvailable("modem") then
print("A modem (from a network/wireless network) card is necessary to use this program. Thanks!")
return
end
local m = component.modem
local ap = component.access_point
if not m.isWireless() then
print("This modem should be from a wireless network card. Please replace the network card with a wireless network card.")
return
end
print("Please enter desired range for listening/relaying: ")
local strrange = io.read()
local range = tonumber(strrange)
ap.setStrength(range)
print("Listening/Relay range set to "..range)
print("Opening ports for listening (1-20)...")
local portnum = 20
while portnum>0 do
m.open(portnum)
portnum = portnum - 1
end
print("Confirming ports are open...")
local portscan = 20
while portscan>0 do
if m.isOpen(portscan) then
print("Port: "..portscan.." is ready.")
else
print("Issue with port: "..portscan..". This port is not open.")
end
portscan = portscan - 1
end
print("Ports have been opened. Awaiting message...")
local _, _, from, port, _, message = event.pull("modem_message")
print("Got a message from " .. from .. " on port " .. port .. ": " .. tostring(message))
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Hey guys!
I'm trying to play around with basic network messages and the like (i.e. tell it the port to broadcast on, the message, and the strength desired), and so I created a counterpart listening program to open ports 1-20 and report whether they're functional or non-functional, and then it moves on to waiting for the message. Issue is, when I open the ports up, only ports 20, 10, and 1 actually report being functional, the others all seem to be closed, any ideas?
Broadcast program:
Listening program:
Thanks for any and all help, guys!
Link to post
Share on other sites