This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Vlgs206's profile picture

Help With Error in File Transfer Script (Rednet Receive expected number, got number)

Started by Vlgs206, 04 April 2018 - 12:34 AM
Vlgs206 #1
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

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()
Bomb Bloke #2
Posted 05 April 2018 - 02:09 AM
That there's a bug in your ComputerCraft installation. You need an update.

As the fix wasn't implemented until the day after Dan posted 1.80pr1 (the build currently offered in the beta discussion area), you'll want to go either here or here.
Edited on 05 April 2018 - 12:10 AM
Vlgs206 #3
Posted 05 April 2018 - 03:49 AM
Ok, Thanks!