Jump to content




Rednet file sharing question

computer lua wireless

5 replies to this topic

#1 Galactica4

  • Members
  • 44 posts
  • LocationAustralia

Posted 13 July 2013 - 08:00 PM

Hi everyone
I am making an Rednet program that multiple computers connect to a central computer that distributes files but they are all on the same channel and I need a way to have the central computer automatically detect which computer on the network sent it a message so it can automatically send a message back based on what you sent it. i already have a way to send files over rednet. this may be confusing so I am going to e explain in the order of events that I want to happen

1 . An local computer (we are going to call this client1) needs a file that is remotely stored on another computer (server computer)
2. Another computer (client2) also needs some files stored on the server computer
3. Client 1 send the keyword for the file that it needs to the server computer (the keyword is keyword)
4. Server computer receives an message (the keyword) on the file sharing channel and detects which computer (client1) sent the message and sends the appropriate file back.
5. Client 2 does the same thing but with a different keyword for file/files

Now I want a way for the server computer to recognize the difference and send the required file to the computer that requested it ie the files don't mix and go to both computers
:)
Confusing huh?


#2 CCJJSax

  • Members
  • 262 posts

Posted 13 July 2013 - 08:34 PM

I haven't really messed with rednet, I'm sad to say. However, I would assume your issue might require fs.open() or fs.write(). look here under the "F" section and it'll have some of the things you're looking for. I'm not the most knowledged in this area and I wouldn't be totally shocked if I'm wrong. I'm actually studying up as we speak on a similar issue.

#3 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 13 July 2013 - 08:39 PM

See below for a better response
Spoiler


#4 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 13 July 2013 - 08:44 PM

Actually, although my above post would work, now that I think on it there is a far easier way to go about this -- just use the return channel to specify what computer should save the file.

For example, when you are sending a rednet message, you provide it with these arguments:
modem.transmit([recipient], [return channel], [message])

And on the receiving end, the client would pull an event like this:
local event, peripheral_side, sender, return_channel, message, distance = os.pullEvent()

So, just specify what computer should save the file with the return channel like this:

Example Client code:
local modem = peripheral.wrap([side])
local function makeRequest(file)
  modem.transmit(shared_channel, os.getComputerId(), "some_file") --#Transmit the request using the shared channel and the computerID as the return channel
  local event = {os.pullEvent("modem_message")} --#Wait for the server to send back the requested file
  if event[3] == shared_channel and event[4] == os.getComputerId() then --#If the sent on channel is the shared_channel and the return channel is the computer id...
    saveFile(event[5]) --#Go ahead and save the file
  end
end

Example server code:
local modem = peripheral.wrap([side])
local function onRequest(file, id) --Whenever the server gets a request, provide it with the message and the return id
  local file_content = getFileContents(file) --#Read the file
  modem.transmit(shared_channel,id,file_content) --#Transmit the file to the receiver, using the same return id
end


#5 Galactica4

  • Members
  • 44 posts
  • LocationAustralia

Posted 13 July 2013 - 09:22 PM

View PostBubba, on 13 July 2013 - 08:44 PM, said:

Actually, although my above post would work, now that I think on it there is a far easier way to go about this -- just use the return channel to specify what computer should save the file.

For example, when you are sending a rednet message, you provide it with these arguments:
modem.transmit([recipient], [return channel], [message])

And on the receiving end, the client would pull an event like this:
local event, peripheral_side, sender, return_channel, message, distance = os.pullEvent()

So, just specify what computer should save the file with the return channel like this:

Example Client code:
local modem = peripheral.wrap([side])
local function makeRequest(file)
  modem.transmit(shared_channel, os.getComputerId(), "some_file") --#Transmit the request using the shared channel and the computerID as the return channel
  local event = {os.pullEvent("modem_message")} --#Wait for the server to send back the requested file
  if event[3] == shared_channel and event[4] == os.getComputerId() then --#If the sent on channel is the shared_channel and the return channel is the computer id...
	saveFile(event[5]) --#Go ahead and save the file
  end
end

Example server code:
local modem = peripheral.wrap([side])
local function onRequest(file, id) --Whenever the server gets a request, provide it with the message and the return id
  local file_content = getFileContents(file) --#Read the file
  modem.transmit(shared_channel,id,file_content) --#Transmit the file to the receiver, using the same return id
end

View PostBubba, on 13 July 2013 - 08:39 PM, said:

See below for a better response
Spoiler

Wow, it is going to take a while to understand this, I also thought that i could sen the computer ID in the message but, this is going to take some time to make!

Btw the program/s iam making is called Fibr, Fibr Fetch and Fibr Share, to be released soon and then included in my upcoming OS :)

#6 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 13 July 2013 - 09:48 PM

View PostGalactica4, on 13 July 2013 - 09:22 PM, said:

I also thought that i could sen the computer ID in the message but

Well you certainly could. In fact, that was what I was originally suggesting. But using the return channel would probably be easier to implement because it wouldn't require comparison of strings or regex :) However, if you would prefer to include it in the message see the first post I made.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users