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

filenet -send files over rednet

Started by Kouksi44, 13 August 2014 - 09:01 PM
Kouksi44 #1
Posted 13 August 2014 - 11:01 PM
FILENET-SEND FILES OVER REDNET




Introduction


This a new version of my file transfer api for rednet. The first one was pretty crappy and this one is probably crappy too but yet much better than the first one.

The new version is 1.0 and has a lot more functions than the old one ! (see functions section)

You can (wow..surprise) send /receive files but also blacklist spezial computrer IDs. Any file sent by these computers will be ignored by the receiver.(You can unlock those IDs aswell if you trust them again)

The thing I am most proud of(although it may be fairly easy for others) is the new ASyncReceiveFile() function. This function runs completely in background and won´t block any other functions of your program

Normally if you do this:



tbl={ rednet.receive()}
print("Hello World")


It would stop at :


rednet.receive()

And print "Hello World" only after a rednet message came in !


With ASyncReceiveFile() , "Hello World" will be printed immidiately . For those people who do not need this function there is a normal receiveFile() that works just like rednet.receive().

The receive function does only return the senderID because everything else is handled automatically(message is written to file,protocol is used internally, distance isn´t used anymore)


Functions


Spoiler


function openSide()



function getVersion()



function blacklist(id)



function removeBlacklist(id)



function sendFile(path,receiverID)



function broadcastFile(path)



function ASyncReceiveFile(path,timeout,override) --override is a bool ; when true the file that is getting received overwrites the existing file with the given name;



function receiveFile(path,timeout,override) --override is a bool ; when true the file that is getting received overwrites the existing file with the given name;



The spezial thing about ASyncReceive is, that it does not stop the program and listens for messages . So the user can use the program just as normal and the message is received in background !





As always, the used code is no masterpiece at all and I am sure there many other solutions that may be even better :)/>




In Minecraft type : pastebin get uh4scAu1 filenet


If there are any bugs please report them !


Hope you like it !



mfG Kouksi44
Edited on 09 November 2014 - 08:00 AM
Kouksi44 #2
Posted 08 November 2014 - 09:58 PM
Small bug fix out.
ShadowLamp #3
Posted 08 November 2014 - 10:47 PM
I don't understand how you use this…
Kouksi44 #4
Posted 09 November 2014 - 08:59 AM
No Problem :)/>

Put this on the first computer :
Spoiler

os.loadAPI("/filenet")

filenet.openSide() -- this does the same as rednet open but this will automatically find the side with the modem.

filenet.sendFile("/testfile",receiverID) -- this send the file named "testfile" (if it exists) to your other computer (you have to insert the ID of the other computer )

and this on the second one :
Spoiler


os.loadAPI("/filenet")
filenet.openSide()
filenet.receive("/testfile") -- this will receive any file sent to the computer and save it as "testfile"


I am going to make a more detailed example later because right now I am on my mobile phone :)/>

Hope you get it now (or atleast more than before )

mfG Kouksi44
ShadowLamp #5
Posted 09 November 2014 - 07:16 PM
I'm getting the error

startup:5: attempt to call nil
Kouksi44 #6
Posted 09 November 2014 - 07:32 PM
Oh excuse me it should be
filenet.receiveFile("/testfile")
instead of
  filenet.receive() 

EDIT: Aaand you need to write filenet.receiveFile("/testfile",false) . Then it will definitely work :)/> (false is the boolean for overwrite. If true the existing file with the same name will be overwritten)
Edited on 09 November 2014 - 06:44 PM
ShadowLamp #7
Posted 09 November 2014 - 07:38 PM
Ah, thank you :)/>
Kouksi44 #8
Posted 09 November 2014 - 08:05 PM
I would suggest you update filenet once because there were a few bugs that should be fixed now ! :)/>
ShadowLamp #9
Posted 09 November 2014 - 08:54 PM
I added the two bits of code and named them startup, when I run these (on the receiver side) I get the error

Expected valid path,number,boolean,got path, nil ,nil

Edit: I didn't see your edit until just now :3 It's working perfectly now, thank you

One more problem:

I created a file on the client computer called "testfile" and inside it had
print("Hello World")

On the receiver side, it got the file, but it had nothing in it…
Kouksi44 #10
Posted 09 November 2014 - 09:03 PM
Uhm wait a second I am going to test this

EDIT: I updated the pastebin link. For me it works now please test it and tell me if it works for you too :)/>
Edited on 09 November 2014 - 08:18 PM
ShadowLamp #11
Posted 09 November 2014 - 09:38 PM
Same error thrown on server side.

Could you give me step by step instructions? I feel like I'm getting lost somewhere…
Kouksi44 #12
Posted 09 November 2014 - 09:42 PM
Hm I don't think its your fault that its Not working :)/>/> You say same error thrown ? Which error ? I will have a look at the receive function as it seems that this one does not work properly :/

EDIT: I found a bug ! I am not sure if it's the one causing the problem but I will fix it till tomorrow (sorry it's late in my country and I got school tomorrow :)/> )
Edited on 09 November 2014 - 08:46 PM
ShadowLamp #13
Posted 09 November 2014 - 10:05 PM
It's 10PM here and I have school too, so I wouldn't be editing it anyway xD
ShadowLamp #14
Posted 10 November 2014 - 06:02 PM
I got this working btw, it's great!

I'd suggest trying to use this as an instant messager!
Kouksi44 #15
Posted 10 November 2014 - 08:58 PM
waaaaait :D/> you got it working ? Then it seems like you are better than me :D/> I found some bugs that can be pretty fatal so I need the next few days to fix those !

It would be very interesting to know what exactly you did !

(Just a tip: type "list" in the terminal and look if there's a file called "rednet_message" , thats one of those Bugs that I need to fix right now :)/> )
Kouksi44 #16
Posted 11 November 2014 - 07:54 PM
BUG FIX OUT ! :)/> everything should work now!