Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("I am the server")
- -- server
- local modemSide = "right"
- local filesList = {
- cake = "/cake",
- can = "/can",
- case = "/case",
- computer = "/computer",
- foot = "system/foot",
- krypt = "/krypt",
- mouse = "home/mouse",
- notepad = "/notepad",
- pen = "/pen",
- test = "/test"
- }
- rednet.open(modemSide)
- while true do
- local event, senderId, message, distanceSent = os.pullEvent("rednet_message") -- only pull rednet events
- local packet -- forward declaration
- print('got a request from '..senderId..' for '..message)
- if filesList[message] then -- if the requested file exists
- local handle = fs.open(filesList[message], "r")
- if not handle then -- if we cannot open the file for some reason
- packet = { success=false, message="Could not open desired file" }
- else
- packet = { success=true, message=handle.readAll(), path=filesList[message] } -- read the file into our packet
- handle.close() -- close the file
- end
- else
- packet = { success=false, message="No program with that name" }
- end
- rednet.send(senderId, textutils.serialize(packet)) -- send our packet
- end
- rednet.close(modemSide)
Advertisement
Add Comment
Please, Sign In to add comment