Stuck in rednet project
#1
Posted 24 August 2012 - 06:24 PM
I have tried some things, but cant make it work except if I put everything in the file to send on 1 line!
please help...... thanx in advance
#2
Posted 24 August 2012 - 06:29 PM
On the other hand, you can send individual lines across, and have a program designed to catch all these lines and put them into a file for you.
#3
Posted 24 August 2012 - 06:42 PM
#4
Posted 24 August 2012 - 06:47 PM
#5
Posted 24 August 2012 - 07:08 PM
Okay so first: how are you parsing the programs to a line presently? Because, it might look something like this.
function sendFile(inFile) -- Needs to be a table/file from fs.open or io.open,and in read mode. local outtro while true do testro = inFile.readLine() if testro then outtro = outtro .. "n" .. testro else break end end return outtro end
That would dump a file into a line with line breaks, ready for sending. You might even be able to call the function in the send call.
The other way would be
function sendFileSep(target, inFile) -- target need to be a vaild computer. inFile needs to be a table/file from fs.open or io.open,and in read mode. while true do testro = inFile.readLine() if testro then rednet.send(target) else break end end end
I don't know that either way will work great, or at all, but they should.
#6
Posted 24 August 2012 - 07:08 PM
#7
Posted 24 August 2012 - 07:23 PM
OmegaVest, on 24 August 2012 - 07:08 PM, said:
Okay so first: how are you parsing the programs to a line presently? Because, it might look something like this.
function sendFile(inFile) -- Needs to be a table/file from fs.open or io.open,and in read mode. local outtro while true do testro = inFile.readLine() if testro then outtro = outtro .. "n" .. testro else break end end return outtro end
That would dump a file into a line with line breaks, ready for sending. You might even be able to call the function in the send call.
The other way would be
function sendFileSep(target, inFile) -- target need to be a vaild computer. inFile needs to be a table/file from fs.open or io.open,and in read mode. while true do testro = inFile.readLine() if testro then rednet.send(target) else break end end end
I don't know that either way will work great, or at all, but they should.
sender:
function sendFile(inFile) -- is only the direction i changed that local inFile = fs.open(inFile,"r") local outtro ={} while true do local testro = inFile.readLine() if testro then table.insert(outtro,testro) else break end end return textutils.serialize(outtro) endreciever:
function recieveFile(inString,Savepath) -- Serialized string and Savepath local file = fs.open(Savepath,"w") local data=textutils.unserialize(inString) for x=1,#data do file.writeLine(data[x]) end file.close() end
#8
Posted 24 August 2012 - 07:27 PM
#9
Posted 24 August 2012 - 07:32 PM
toOut = sendFile(file) rednet.send(target, toOut)
flipped = rednet.receive()
Either Kolpa or my functions will work out
Both sendFile functions (basically) send over a long line of "code". This just needs to be ported to a file (in my case), or decomplied and put to a file (in Kolpa's, who has graciously included a decompiler as well).
#10
Posted 24 August 2012 - 07:37 PM
bios:206"[string "isend"] : 6: '='expected
(did this with kolpa`s sender code)
#11
Posted 24 August 2012 - 07:41 PM
#12
Posted 24 August 2012 - 07:51 PM
sender:
function sendFile(inFile) -- is only the direction i changed that local inFile = fs.open(inFile,"r") local outtro ={} while true do local testro = inFile.readLine() if testro then table.insert(outtro,testro) else break end end inFile.close() return textutils.serialize(outtro) end data = sendFile("filename") rednet.send(pcid,data)reciever:
function recieveFile(inString,Savepath) -- Serialized string and Savepath local file = fs.open(Savepath,"w") local data=textutils.unserialize(inString) for x=1,#data do file.writeLine(data[x]) end file.close() end _,text = rednet.receive() recieveFile(text,"path")
#13
Posted 24 August 2012 - 07:52 PM
It would actually be better used thusly:
file = fs.open("test", "r") toOut = sendFile(file) file.close() rednet.send(target, toOut)
I'm not sure this is or isn't what you did. But, on the other computer, put Kolpa's code into a program and have it do this.
inFile = rednet.receive() file = fs.open("test2", "w") file.close() -- Should make the file for you receiveFile(inFile, "test2")
And there ya go. If I understand everything right this should work
EDIT: Crap. Ninja'd. Again. And better, no less.
#14
Posted 24 August 2012 - 08:00 PM
#16
Posted 24 August 2012 - 08:14 PM
#17
Posted 25 August 2012 - 06:19 AM
#18
Posted 25 August 2012 - 06:44 AM
sender: rednet:347: positive number expected
rednet.open("right") print ("Please enter the receiver ID: ") ID = read() print ("Please enter the file directory: ") filename = io.read() inFile = fs.open(filename, "r") function sendFile (inFile) local outtro={} while true do testro = inFile.readLine() if testro then table.insert(outtro,testro) else break end end return textutils.serialize(outtro) end file = fs.open(filename, "r")data = sendFile(file) file.close() rednet.send(ID,data) print ("File send!")</name>
receiver: bios:206: [string "iget"]:8:8 '<name>' expected
rednet.open("right") print ("Please enter filename: ") Savepath = read() function recieveFile(inString,Savepath) file = fs.open(Savepath,"w") local data=textutils.unserialize(inFile) for x,#data do file.writeLine(data[x]) end file.close() end _,text = rednet.receive() recieveFile(text,path)
I now some stuff about computercraft, but what there errors are about...... />
#19
Posted 25 August 2012 - 07:15 AM
rednet.open("right") print ("Please enter the receiver ID: ") ID = assert(tonumber(read()), "Not a number") print ("Please enter the file directory: ") filename = io.read() inFile = fs.open(filename, "r") function sendFile (inFile) local outtro={} while true do testro = inFile.readLine() if testro then table.insert(outtro,testro) else break end end return textutils.serialize(outtro) end file = fs.open(filename, "r")data = sendFile(file) file.close() rednet.send(ID,data) print ("File send!")and (receiver):
rednet.open("right") print ("Please enter filename: ") Savepath = read() function recieveFile(inString,Savepath) file = fs.open(Savepath,"w") local data=textutils.unserialize(inFile) for onlyalittlenumber=x,#data do file.writeLine(data[x]) end file.close() end _,text = rednet.receive() recieveFile(text,path)
#20
Posted 25 August 2012 - 07:45 AM
To the person above me, your signature is too big.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users