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

How To Send Data Between Computers

Started by jjjhfam, 04 July 2015 - 01:13 AM
jjjhfam #1
Posted 04 July 2015 - 03:13 AM
Some may consider this a noob question, but I've only really been using ComputerCraft for a couple months and I've never seen how to send regular data between computers. How would I accomplish this?
Bomb Bloke #2
Posted 04 July 2015 - 03:42 AM
Generally with the rednet API. Slap modems on your computers, open the relevant sides, then proceed to send and receive.
jjjhfam #3
Posted 04 July 2015 - 04:12 AM
Nice rhyme :)/>. I now have two questions.

1. How would I specify/find the ID of a computer?

2. Are the rednet.send() protocols user-specified or is there a set list of them?
Bomb Bloke #4
Posted 04 July 2015 - 04:57 AM
1. How would I specify/find the ID of a computer?

If you type "id" into a given computer's command line, it'll give you its ID number. If you instead want your two systems to figure it out automagically, incorporate rednet.lookup() into your scripts.

2. Are the rednet.send() protocols user-specified or is there a set list of them?

They're user-defined, and can be pretty much whatever you want.

However, avoid the string "dns" - that one's used by the rednet lookup system, which'll get confused if you try it.
jjjhfam #5
Posted 04 July 2015 - 05:03 AM
Thanks for the help and quick response!
cmdpwnd #6
Posted 04 July 2015 - 05:17 AM
a slighty easier way to do this in the case that you want to communicate with a select number of devices (multicast) instead of broadcasting to all devices using rednet is if you use the modem api - http://www.computercraft.info/wiki/Modem_(API) and transmit over a selected channel


sendChan = 100
recvChan = 100

--Send
local data = "Hello"
modem.transmit(sendChan,recvChan,data)
--/Send

--Recv
while true do
  event = {os.pullEvent()}
  if event and event[2] == "modem_message" and event[4] == recvChan then
	return event[6]
  end
end
--/Recv
Edited on 04 July 2015 - 11:56 PM