Posted 04 April 2018 - 02:34 AM
This is my first time posting on the forums, so my apologies if I botch the format. I also realize that a majority of my code may be redundant or broken (I am new to coding.)
I was trying to create a file transfer program that sends a file from a server to a client using rednet. The part of the code I am trying to fix is supposed to time out after 2 seconds. Instead, I am receiving the error "fileGrab.lua:13: bad argument #2 (expected number, got number)". Is this error on my end, or is it a bug? Any insight would be appreciated. Thanks.
Client Code
Server Code
I was trying to create a file transfer program that sends a file from a server to a client using rednet. The part of the code I am trying to fix is supposed to time out after 2 seconds. Instead, I am receiving the error "fileGrab.lua:13: bad argument #2 (expected number, got number)". Is this error on my end, or is it a bug? Any insight would be appreciated. Thanks.
Client Code
rednet.open("top")
rednet.broadcast("true","readyFS")
id,msg = rednet.receive("fileList")
msg2 = msg
print("Files:")
for k,v in ipairs(msg) do
print(v)
end
print("Choose Your File:")
fr = io.read()
rednet.broadcast(fr,"sendFile")
print(type(2))
id,msg = rednet.receive(2)
if msg ~= msg2 then
file = fs.open(fr,"w")
file.write(msg)
file.close()
print("Done!")
else
id,msg = rednet.receive("error")
print("An Error has Occured: "..msg)
end
print("Task Completed")
Server Code
function begin()
rednet.open("top")
while true do
print("Opened port: ")
rednet.receive("readyFS")
files = fs.list("")
rednet.broadcast(files,"fileList")
id,msg,prtcl = rednet.receive("sendFile")
if fs.isDir("msg") == true then
sleep(3)
rednet.broadcast("Cannot send directory.","error")
begin()
end
msge = fs.exists(msg)
if msge == false then
sleep(3)
rednet.broadcast("File does not exist.","error")
begin()
end
file = fs.open(msg,"r")
send = file.readAll()
file.close()
rednet.broadcast(send,"fileSent")
end
end
begin()