I am currently writing an API to send files over rednet.
In my API I am offering the sender the possibility to give the file an "alias". This alias will be the name of the file on the receiver computer.
I wanted to send this alias by using it as the protocol name of the message.
Now I have to get this protocol at the receivers computer to get the name of the file and thats the point where my program crashes.
Here´s the code of the API :
function sendFile(path,alias,receiverID)
openSide()
if fs.exists(path)
then
local g=fs.open(path,"r")
local file=g.readAll()
else print("error:invalid path")
end
if alias==""
then
local filealias=fs.getName(path)
else filealias=alias
end
rednet.send(receiverID , file , filealias)
end
function receiveFile(path,timeout)
openSide()
senderID,message,protocol=rednet.receive(timeout)
local l=fs.open(path..protocol,"w")
l.write(message)
end
In line 49 my program crashes saying: attempt to concatenate string and nil;
Obviously the main problem is this part :
senderID,message,protocol=rednet.receive(timeout)
Here I try to get the protocol of the message, but somehow this doesn´t work :/
Any ideas how to fix this ?
Thank you in advance,
Kouksi44