Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CLIENT SERVER PROOF OF CONCEPT
- CLIENT::::::
- local compid
- local alv3
- local function Startup()
- term.clear()
- term.setCursorPos (1,1)
- rednet.open("right")
- print (" this Computer's id: ", os.getComputerID())
- print (" Set receiving computer's id:")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- print ()
- print (" message:")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- term.setCursorPos(5,4)
- repeat
- compid = tonumber(read())
- until compid
- term.setCursorPos(5,4)
- print ("id saved")
- term.setCursorPos(5,9)
- alv3 = read()
- term.setCursorPos(5,9)
- print ("message saved")
- sleep(0.5)
- Sender()
- Receive()
- end
- function Sender()
- term.clear()
- term.setCursorPos (1,1)
- print ("sending message in: ")
- print ("3")
- sleep(1)
- print ("2")
- sleep(1)
- print ("1")
- sleep(1)
- rednet.send(compid, alv3)
- sleep(1)
- print ("message sent")
- sleep(1)
- end
- function Receive()
- term.clear()
- term.setCursorPos (1,1)
- print (" this Computer's id: ", os.getComputerID())
- print (" waiting for message:")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- print ()
- print (" Terminal:")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- while true do
- rednet.open("right")
- senderID, message = rednet.receive()
- term.setCursorPos (5,4)
- print (message)
- sleep(0.5)
- term.setCursorPos (5,9)
- print (senderID)
- local event = os.pullEvent("key")
- rednet.close("right")
- Startup()
- break
- end
- end
- Startup()
- SERVER::::::
- local compid
- local MFile = "messages.txt"
- local function Startup() -- set computerLabel, other computers id, and Launch WriteFile()
- term.clear()
- term.setCursorPos (1,1)
- print (" this Computer's id: ", os.getComputerID())
- print (" Set this Computer's label:")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- print ()
- print (" Set The Computer Terminal's ID")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- term.setCursorPos(5,4)
- local IgnLabel = read()
- os.setComputerLabel(IgnLabel)
- term.setCursorPos(5,4)
- print ("Label successful")
- term.setCursorPos(5,9)
- repeat
- compid = tonumber(read())
- until compid
- term.setCursorPos(5,9)
- print ("ID saved")
- sleep(2)
- print ("storing message")
- WriteFile()
- sleep(1)
- print ("sending stored messages")
- sleep(2)
- SendFile()
- print ("message sent!")
- sleep(5)
- Startup()
- end
- function WriteFile() -- store incoming transmission into MFile variable
- rednet.open("right")
- local id, message = rednet.receive()
- rednet.close()
- if fs.isDir("saves") == false then
- fs.makeDir("saves")
- local file = fs.open("saves/"..MFile, "a")
- file.writeLine(message)
- file.close()
- else
- local file = fs.open("saves/"..MFile, "a")
- file.writeLine(message)
- file.close()
- end
- end
- function SendFile() -- send contents of MFile to another computer
- file = fs.open("saves/"..MFile, "r")
- local shipment = file.readAll()
- file.close()
- rednet.open("right")
- rednet.send(compid, shipment)
- rednet.close("right")
- end
- Startup()
Advertisement
Add Comment
Please, Sign In to add comment