Jump to content




Lua - Remote connect


  • You cannot reply to this topic
6 replies to this topic

#1 spook811

  • Members
  • 9 posts

Posted 26 August 2012 - 11:21 PM

Hi, im trying to write a program that will connect to a computer and run a program from their. Like a server, the program is hosted on a central computer, that is accessed by other computers. How do I go about this?

Thanks,
Spook811

#2 funkey100

  • Members
  • 62 posts
  • LocationMars

Posted 26 August 2012 - 11:48 PM

You will need to attach a modem to any side of both computers. Then write this code:

For the server:
id = 3 --Receiving computer id here
side = "top" --Modem side here

rednet.open(side)
file = io.open("data")  --File that contains the code to send
filedata = file:read()
file:close()
rednet.send(id, filedata)
rednet.close(side)

Reciever:
side = "top" --Modem side here

rednet.open(side)
file = io.open("data", "w")
id, msg = rednet.receive()
file:write(msg)
file:close()
rednet.close(side)
shell.run("data")

Please tell me if that was helpful!

#3 funkey100

  • Members
  • 62 posts
  • LocationMars

Posted 27 August 2012 - 12:06 AM

Here is a MUCH BETTER CODE because you don't have to make new files!

For the server:
id = 3 --Receiving computer id here
side = "top" --Modem side here

while true do
filedata = read()
rednet.open(side)
rednet.send(id, filedata)
rednet.close(side)
end

Reciever:
side = "top" --Modem side here

while true do
rednet.open(side)
id, msg = rednet.receive()
rednet.close(side)
file = io.open("data", "w")
file:write(msg)
file:close()
shell.run("data")
fs.delete("data")
end


#4 spook811

  • Members
  • 9 posts

Posted 27 August 2012 - 12:28 AM

Server gets no further than the read part and computer / reviver gets no further than receive...

#5 funkey100

  • Members
  • 62 posts
  • LocationMars

Posted 27 August 2012 - 12:59 AM

Did you place the modem on the top? Did you edit top to something else if you didn't put the modem on the top? Did you type your command when it says the read()? Did you edit the computer ID to the computer you want to send to? What errors did you get, if any?

#6 spook811

  • Members
  • 9 posts

Posted 27 August 2012 - 01:18 AM

modem was on right side so was "right",computer ID is 57, no errors.

Thanks,
Spook811

#7 funkey100

  • Members
  • 62 posts
  • LocationMars

Posted 27 August 2012 - 07:31 PM

So did it work or not?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users