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

[1.5+] In-depth Modem Channels Tutorial

Started by Bubba, 09 February 2013 - 04:18 PM
Bubba #1
Posted 09 February 2013 - 05:18 PM
Note: This tutorial only applies to ComputerCraft versions 1.5+ It does not work for anything pre-1.5

Well this is the addition that you (and every hacker who ever used ComputerCraft) has been waiting for. The joy of having to create a whole new layer of security on top of our rednet enabled programs is finally upon us, and oh what glorious fun we will have. Those awful, infallibly secure modems will no longer be tolerated! What is this addition that I speak of? The introduction of channels to rednet!

What are channels exactly? Well in terms of ComputerCraft, channels are, quite simply, an open network which you can send and receive rednet messages on. There are several advantages to this, but I will leave it to you to deduce what they are.

How do channels work? Well first off, you're going to have to come to terms with the fact that you cannot access channel functionality through the rednet API. To use this awesome new feature, we're going to have to do some hardcore peripheral wrapping.


--So you want to use channels, eh?
--The first thing you'll need to do is wrap your modem													 '
--My modem just happens to be on the top of the computer, but you can place modems on any side
local modem = peripheral.wrap("top") --Wow. That was easy.

Yup. That's it. Now you have access to all of the functions which a modem has through the "modem" variable. These exposed functions are:

modem.open(integer channel)
modem.isOpen(integer channel)
modem.transmit(integer channel, integer replyChannel, string message)
modem.close(integer channel)
modem.closeAll()

Opening channels:
Opening channels is simple. All you have to do is…

local desiredChannel = 1
modem.open(desiredChannel)
But what does opening a channel mean exactly? Well, until you've opened a channel you cannot receive any messages on that channel. You can send messages though, so if all you need to do is send a bunch of messages then there is no need to open a channel.
Note: You can open 128 channels at any given time and receive messages on them.
Note 2: The largest channel you can open is 65535

Transmiting messages:
Transmitting messages is pretty simple too. Use the transmit function like so:

local sendOnChannel = 1
local replyChannel = 2
modem.transmit(sendOnChannel, replyChannel, "Ping!")
--[["
You've just sent a message on channel 1. Any computers that have opened
channel 1 can receive the message. You've also specified that the computer
should reply on channel 2.
"--]]

Receiving messages:
Receiving a message is simple as well. Everything boils down to events!

local modem = peripheral.wrap("top")
modem.open(1) --Receive messages from computers sending on channel 1
modem.open(2) --Opening channel 2 just for the heck of it
local messageArguments = {os.pullEvent("modem_message")}
for i,v in pairs(messageArguments) do
  print(v)
end
This will output the following if you use my transmit message code from above:

modem_message
top
1
2
Ping!
3 --This is the distance that two computers are apart.

And that's it! Channels are actually fairly simple, but as you can imagine they can be quite powerful.

Edit: Since I noticed that there was some confusion about being able to open more than one channel at the same time, here is an example of doing just that.

local modem = peripheral.wrap("top")
local userChannels = { --Define the channels that regular users send on
	[1] = true;
	[3] = true;
	[5] = true;
	[7] = true;
}

local adminChannels = { --Define the channels that admins send on
	[2] = true;
	[4] = true;
	[6] = true;
	[8] = true;
}

for i=1,8 do --Open all of the aforementioned channels
	modem.open(i)
end

while true do
	local message = {os.pullEvent("modem_message")} --Receive messages
	if userChannels[message[3]] then --If that message is sent on a channel that is defined in userChannels then
		print("User channel")
	else
		print("Admin channel")
	end
end

Adieu,

Bubba
theoriginalbit #2
Posted 09 February 2013 - 06:09 PM
Nice :)/> I'm glad someone has done this, saves me having to figure it out later ;)/>

I can see several advantages to channels, one being [censored so people have to figure it out] :P/>

So does the "rednet_message" event still exists?
Bubba #3
Posted 09 February 2013 - 06:15 PM
Nice :)/> I'm glad someone has done this, saves me having to figure it out later ;)/>

I can see several advantages to channels, one being [censored so people have to figure it out] :P/>

So does the "rednet_message" event still exists?

Nope. Apparently it's been removed completely.
theoriginalbit #4
Posted 09 February 2013 - 06:25 PM
Nice :)/>/> I'm glad someone has done this, saves me having to figure it out later ;)/>/>

I can see several advantages to channels, one being [censored so people have to figure it out] :P/>/>

So does the "rednet_message" event still exists?

Nope. Apparently it's been removed completely.
Well how the hell is that "backward compatible with older versions"?!
lieudusty #5
Posted 09 February 2013 - 08:03 PM
Nice tutorial on modems and channels :D/>
ElvishJerricco #6
Posted 09 February 2013 - 08:15 PM
Nice :)/>/> I'm glad someone has done this, saves me having to figure it out later ;)/>/>

I can see several advantages to channels, one being [censored so people have to figure it out] :P/>/>

So does the "rednet_message" event still exists?

Nope. Apparently it's been removed completely.
Well how the hell is that "backward compatible with older versions"?!

At least the Rednet API functions the same.
theoriginalbit #7
Posted 09 February 2013 - 08:42 PM
At least the Rednet API functions the same.
The only thing I use from that is the rednet.send… I make my own event loops, meaning that all my programs will now need to say

if event[1] == "rednet_message" or event[1] == "modem_message" then

Although I do like how the side is returned for the message, means there is finally a use to turning on multiple modems…
redeye83 #8
Posted 10 February 2013 - 02:37 AM
cool tutorial, I'm sure I will find a use for this on one of my projects.

One question, you said
[quote=Bubba]
The joy of creating a whole new layer of security on top of our rednet enabled programs is finally upon us, and oh what glorious fun we will have.


How does this make it more secure?
theoriginalbit #9
Posted 10 February 2013 - 02:51 AM
How does this make it more secure?
Think about it… but you can only receive on one specific channel at a time (from one modem)… and there are lots of channels… why do u think this makes it more secure?
redeye83 #10
Posted 10 February 2013 - 02:54 AM
How does this make it more secure?
Think about it… but you can only receive on one specific channel at a time (from one modem)… and there are lots of channels… why do u think this makes it more secure?
I'm hoping its because I has ninja stars but I doubt it lol. My next question was if you could just open every channel at once and "snoop" for any messages. But surly it would then just be a case of opening and closing every channel one after the other until it gets a messages and then will keep listening on that channel and recording everything?
theoriginalbit #11
Posted 10 February 2013 - 02:58 AM
I'm hoping its because I has ninja stars but I doubt it lol.
No. It means that modems listening on another channel wouldn't get the message, ergo, more security…

My next question was if you could just open every channel at once and "snoop" for any messages. But surly it would then just be a case of opening and closing every channel one after the other until it gets a messages and then will keep listening on that channel and recording everything?
I don't think you can set it to listen on all… but since you change it with the peripheral then it should allow you to have 6 modems all listening on different channels…
redeye83 #12
Posted 10 February 2013 - 03:05 AM
is there no way to password protect channels? or is there a encryption api already outthere?
theoriginalbit #13
Posted 10 February 2013 - 03:10 AM
is there no way to password protect channels? or is there a encryption api already outthere?
Idk about password protecting… why don't you search for one of the several encryption apis…….. :P/>
remiX #14
Posted 10 February 2013 - 03:29 AM
Nice tutorial for when 1.5 actually comes out.

I only saw the beta testing post now (5 minutes ago) and didn't feel like testing it in game xD
CastleMan2000 #15
Posted 10 February 2013 - 04:29 AM
This topic is incredibly helpful! Thank you!
MudkipTheEpic #16
Posted 10 February 2013 - 04:54 AM
Wow… Code for snooping on all channels…

modem = peripheral.wrap(modemside)
for i=0, 65535 do – Or how ever many channels there are
modem.open(i)
end

Would this allow you to snoop on rednet.send messages?

Edit: Wait.. can you only listen on 1 chaannel?
Bubba #17
Posted 10 February 2013 - 05:00 AM
I don't think you can set it to listen on all… but since you change it with the peripheral then it should allow you to have 6 modems all listening on different channels…


You can listen on as many channels as you want simultaneously with only one peripheral. I'll put this in the tutorial so people are aware of it.
Edit: The advantage to having more than one modem connected is really just for ease of use. For example, if you're building a chat program and you want administrators to be able to send commands, they can do so on one channel which the modem on the left side will receive, and regular messages will be sent to another channel which the modem on the right side will receive. This will make it easier to identify and separate the two categories when receiving messages.

How does this make it more secure?

It doesn't. I was actually be sarcastic xD

Wow… Code for snooping on all channels…

modem = peripheral.wrap(modemside)
for i=1, 65535 do – Or how ever many channels there are
modem.open(i)
end

Would this allow you to snoop on rednet.send messages?

Perfectly valid code actually.
MudkipTheEpic #18
Posted 10 February 2013 - 05:08 AM
Wow… Code for snooping on all channels…

modem = peripheral.wrap(modemside)
for i=1, 65535 do – Or how ever many channels there are
modem.open(i)
end

Would this allow you to snoop on rednet.send messages?

Perfectly valid code actually.
Valid code for what? Snooping on rednet.send's? Or just listening on all channels?
Bubba #19
Posted 10 February 2013 - 05:12 AM
Valid code for what? Snooping on rednet.send's? Or just listening on all channels?

Opening that many channels, and in the process making the modem throw an event every time a message is sent on a channel on or under 65535. All it takes to snoop is to add this:

while true do
  print(os.pullEvent("modem_message"))
end
MudkipTheEpic #20
Posted 10 February 2013 - 05:29 AM
Valid code for what? Snooping on rednet.send's? Or just listening on all channels?

Opening that many channels, and in the process making the modem throw an event every time a message is sent on a channel on or under 65535. All it takes to snoop is to add this:

while true do
  print(os.pullEvent("modem_message"))
end

So rednet.send isn't secure anymore? :o/>
Bubba #21
Posted 10 February 2013 - 05:31 AM
So rednet.send isn't secure anymore? :o/>

Nope :)/> I'm actually very much in favor of this because it simulates real life at least a bit closer. And it's fun encrypting all of your rednet stuff.
BigSHinyToys #22
Posted 10 February 2013 - 06:10 AM
So it swings from totally secure system to a totally susceptible one. where all channels can be monitored at the same time. I don't know if this is a good thing or a bad one ??
Bubba #23
Posted 10 February 2013 - 06:23 AM
So it swings from totally secure system to a totally susceptible one. where all channels can be monitored at the same time. I don't know if this is a good thing or a bad one ??
In terms of being able to monitor every channel at once, yes it's totally susceptible. Maybe this will change though (?). IMO, you should be limited in the number of channels you can open on one modem, but by adding a modem to all 6 sides you would have the full range.
Kingdaro #24
Posted 10 February 2013 - 07:49 AM
I say only one channel per modem. If you're going to be a master rednet hacker, you'd better set up a hugeass computer database.
MudkipTheEpic #25
Posted 10 February 2013 - 08:00 AM
Well, I'd assume it would be at least 25 c/m (channels per modem).
Bubba #26
Posted 10 February 2013 - 08:12 AM
I say only one channel per modem. If you're going to be a master rednet hacker, you'd better set up a hugeass computer database.

Er… I would say at least 5 channels per modem. I would prefer to be able to receive messages on more than 6 channels.


Well, I'd assume it would be at least 25 c/m (channels per modem).

Yeah ideally it would be something closer to this.
Kingdaro #27
Posted 10 February 2013 - 08:18 AM
Yeah, 6 channels a computer would be hell. I just felt like being a little radical.

And now I'm even going to be more radical. The more channels you have open, the higher the chance that your modem will explode! :D/>/> (Or maybe it'd just catch fire - that'd be pretty hilarious. Perhaps a program with an infinite loop causes the computer to catch on fire? That'd be hilarious!)
Bubba #28
Posted 10 February 2013 - 09:15 AM
Yeah, 6 channels a computer would be hell. I just felt like being a little radical.

And now I'm even going to be more radical. The more channels you have open, the higher the chance that your modem will explode! :D/>/> (Or maybe it'd just catch fire - that'd be pretty hilarious. Perhaps a program with an infinite loop causes the computer to catch on fire? That'd be hilarious!)

Actually that would be kinda funny. I would absolutely hate it but it would be funny.
theoriginalbit #29
Posted 10 February 2013 - 01:13 PM
for i=0, 65535 do – Or how ever many channels there are
Good guess.. there are actually that many…
MudkipTheEpic #30
Posted 10 February 2013 - 02:42 PM
for i=0, 65535 do – Or how ever many channels there are
Good guess.. there are actually that many…

Thanks. Tryed to set my channel to like 13379001 or something, errored "must be between 0 and 65535" or something. ;)/>
theoriginalbit #31
Posted 10 February 2013 - 02:46 PM
I learnt it from Cloudy's comment here
http://www.computercraft.info/forums2/index.php?/topic/4677-firewolf-website-browser-239-http-preparation/page__st__220
KingMachine #32
Posted 11 February 2013 - 01:42 AM
I'm very happy to see the channels feature implemented. It makes my job as a computercraft security expert more rewarding.
dan200 #33
Posted 11 February 2013 - 08:19 AM
If you guys check the latest beta version, there's been a few changes:
Modems can only open 128 channels at once.
rednet_message is back again, for backwards compat
digipenguin #34
Posted 13 February 2013 - 11:13 AM
Two things:
1. do modems now have infinite range? If so, then I praise you.
2. thank god everything I send over rednet is already encrypted…
3. digital signature protocols rock…
4. that's a little more than 2 things
5. it just became measurably more secure to use ender chests than rednet… Lol. (only ~4K combinations, but a far higher material cost to scan all of them)
Bubba #35
Posted 13 February 2013 - 12:43 PM
Two things:
1. do modems now have infinite range? If so, then I praise you.
2. thank god everything I send over rednet is already encrypted…
3. digital signature protocols rock…
4. that's a little more than 2 things
5. it just became measurably more secure to use ender chests than rednet… Lol. (only ~4K combinations, but a far higher material cost to scan all of them)

I'm fairly certain that modems do not have infinite range unless you specify that in the config.
digipenguin #36
Posted 15 February 2013 - 03:20 PM
Two things:
1. do modems now have infinite range? If so, then I praise you.
2. thank god everything I send over rednet is already encrypted…
3. digital signature protocols rock…
4. that's a little more than 2 things
5. it just became measurably more secure to use ender chests than rednet… Lol. (only ~4K combinations, but a far higher material cost to scan all of them)

I'm fairly certain that modems do not have infinite range unless you specify that in the config.

So, at least you're safe if you protect your borders (especially during thunderstorms)
Thief^ #37
Posted 16 February 2013 - 12:30 AM
Thanks for this tutorial, I've converted my router api over to using it and I'm very happy with the result :)/>
Abdiel #38
Posted 16 February 2013 - 08:26 AM
Hmm, so there is no more equivalent to rednet.send(computerID, message) to send a message to a specific computer? Is every message now a broadcast to everyone listening on the same channel?
Bubba #39
Posted 16 February 2013 - 10:27 AM
Hmm, so there is no more equivalent to rednet.send(computerID, message) to send a message to a specific computer? Is every message now a broadcast to everyone listening on the same channel?


Indeed. If everyone is using the rednet API rather than direct peripheral access, then your messages are "private" in the sense that nobody has a channel open other than the one corresponding to their ID. But in reality there is no such thing as a private message now when it comes to rednet.
LDShadowLord #40
Posted 18 February 2013 - 09:02 AM
Question, when I use the code provided in this tutorial I get some extra info which I'm not sure on.
Here is an example.
modem_message –Event Triggered
top –Where the modem is
number1 –send channel
number2 –reply channel
message –Standard message
number3 –?????
What is the number 3 which always appears at the bottom?, it's really frustrating me.

EDIT: Did some more testing, it appears to be quite random?
Bubba #41
Posted 18 February 2013 - 09:34 AM
Question, when I use the code provided in this tutorial I get some extra info which I'm not sure on.
Here is an example.
modem_message –Event Triggered
top –Where the modem is
number1 –send channel
number2 –reply channel
message –Standard message
number3 –?????
What is the number 3 which always appears at the bottom?, it's really frustrating me.

EDIT: Did some more testing, it appears to be quite random?

That is the distance between the computers :)/>
LDShadowLord #42
Posted 18 February 2013 - 11:12 AM
Question, when I use the code provided in this tutorial I get some extra info which I'm not sure on.
Here is an example.
modem_message –Event Triggered
top –Where the modem is
number1 –send channel
number2 –reply channel
message –Standard message
number3 –?????
What is the number 3 which always appears at the bottom?, it's really frustrating me.

EDIT: Did some more testing, it appears to be quite random?

That is the distance between the computers :)/>
Aha! Gotcha, thankyou!
DarkWasp #43
Posted 21 February 2013 - 06:53 PM
What is the most efficient way to weed out all of the information other than the message itself?

Aside from a bit of coding I did over a decade ago, my programming experience is about 2 days old now so I still get caught up on the basics from time to time.

Basically what I've got is:

local modem = peripheral.wrap("top")

modem.open(127)

local messageArguments = {os.pullEvent("modem_message")}

table.remove(messageArguments) -- Remove distance
table.remove(messageArguments, 1) 
table.remove(messageArguments, 1)
table.remove(messageArguments, 1)
table.remove(messageArguments, 1) -- Remove everything up until the message itself
  
for i,rawmessage in pairs(messageArguments) do
 
  message = rawmessage
  
print(message)

end

I'm sure it's highly inefficient and I'm curious to know what the best and shortest way to do this. All I want to do is pull only the message out into a variable and leave the rest of the information behind.
theoriginalbit #44
Posted 21 February 2013 - 07:01 PM
What is the most efficient way to weed out all of the information other than the message itself?

- snip -
A table can be accessed by indexes or keys, so you can do this to extract the message and still preserve all the other data, which you will most likely need later.

local modem = peripheral.wrap("top")
modem.open(127)
local messageArguments = {os.pullEvent("modem_message")}
local message = messageArguments[5]
print(message)

have a read of this and this
Edited on 21 February 2013 - 06:02 PM
DarkWasp #45
Posted 21 February 2013 - 07:56 PM
What is the most efficient way to weed out all of the information other than the message itself?

- snip -
A table can be accessed by indexes or keys, so you can do this to extract the message and still preserve all the other data, which you will most likely need later.

local modem = peripheral.wrap("top")
modem.open(127)
local messageArguments = {os.pullEvent("modem_message")}
local message = messageArguments[5]
print(message)

have a read of this and this

Ah, thanks that helps a lot. So much makes more sense now.

Actually this channel feature could not have come at a better time for me.

A friend made a redpower 2 frame elevator for me controlled by GPS, but he hasn't been on since Mindcrack updated CC to 1.5 and much of his rednet code started failing. So far I've been able to learn enough (mostly just by looking through his programs) to debug nearly all of the issues and get the elevator running again. However, I kind of got addicted and decided to vastly improve his elevator call button computers(they use advanced monitors) to display 3 different states when the elevator is moving, on the current floor or on a different floor and ready to be called.

I got it to work for one button, but I need the elevator to send its message to all of the call buttons. Then I read about this channel feature and it's absolutely perfect for that.
Abdiel #46
Posted 23 February 2013 - 04:16 AM
If you're specifically watching for modem messages, and not any other events, you don't need to wrap the event in a table.

local side, messageChannel, replyChannel, message, distance = os.pullEvent("modem_message")
MudkipTheEpic #47
Posted 23 February 2013 - 08:17 AM
If you're specifically watching for modem messages, and not any other events, you don't need to wrap the event in a table.

local side, messageChannel, replyChannel, message, distance = os.pullEvent("modem_message")

No, you forgot the event. It's:
local event, side, messageChannel, replyChannel, message, distance = os.pullEvent("modem_message")
Bubba #48
Posted 23 February 2013 - 11:10 AM
If you're specifically watching for modem messages, and not any other events, you don't need to wrap the event in a table.

local side, messageChannel, replyChannel, message, distance = os.pullEvent("modem_message")

Like Mudkip said, using os.pullEvent(param) will still return the event so you need to capture that as well. But the reason that I use the table is for convenience, not because it is required. Writing args = {os.pullEvent()} is much neater and simpler than having 5 different variables as long as you can remember what each specific event returns.
TwelveEight #49
Posted 25 February 2013 - 09:47 AM
Hm… would it not be possible to set the integer channel to be a variable, then have a loop scan open channels or something?

^Not a detailed question, but just a thought.
Bubba #50
Posted 25 February 2013 - 02:32 PM
Hm… would it not be possible to set the integer channel to be a variable, then have a loop scan open channels or something?

^Not a detailed question, but just a thought.

Yup. Easily possible.


local function listen()
  while true do
	local evts = {os.pullEvent()}
	if evts[1] == "timer" then
	   return
	elseif evts[1] == "modem_message" then
	   print("Message: "..evts[4])
	end
  end
end

local max = 65535
local large = 128
while true do
for i=1, max, large do
  for x=i, i+large do
	modem.open(x)
  end
	os.startTimer(2) --Listen for two seconds and then move on to the next range
	listen()
  for x=1, i+large do
	modem.close(x)
  end
end
end

Of course, the above sample is ridiculously simple and if I were to do this in game I would probably add a table of channels that should always be listened to as soon as one message was received on the channel.
WAKU #51
Posted 12 March 2013 - 04:25 AM
thank u for sharing. That's useful.
Abdiel #52
Posted 12 March 2013 - 10:02 PM
If you're specifically watching for modem messages, and not any other events, you don't need to wrap the event in a table.

local side, messageChannel, replyChannel, message, distance = os.pullEvent("modem_message")

Like Mudkip said, using os.pullEvent(param) will still return the event so you need to capture that as well. But the reason that I use the table is for convenience, not because it is required. Writing args = {os.pullEvent()} is much neater and simpler than having 5 different variables as long as you can remember what each specific event returns.

Apologies for the mistake, you are indeed correct.

Perhaps a cleaner way to do it would be through symbolic constants:

local EVENT = 1
local MODEM_SIDE = 2
local MODEM_MESSAGE_CHANNEL = 3
local MODEM_REPLY_CHANNEL = 4
local MODEM_MESSAGE = 5
local MODEM_DISTANCE = 6
local TIMER_ID = 2

[...]

local timer = os.startTimer(10)
local e = {os.pullEvent()}
if e[EVENT] == "modem_message" then
  msg = e[MODEM_MESSAGE]
  replyChannel = e[MODEM_REPLY_CHANNEL]
  -- process the message

elseif e[EVENT] == "timer" and e[TIMER_ID] == timer then
  print("Timeout")
end
no9name909 #53
Posted 13 March 2013 - 07:09 AM
Thanks for the tutorial but I don't really understand what the reply channel is for with sending a message.
Does it make any difference when I change it to an other number?
Bubba #54
Posted 13 March 2013 - 07:30 AM
Thanks for the tutorial but I don't really understand what the reply channel is for with sending a message.
Does it make any difference when I change it to an other number?

Nope. It's really only there to be useful. I could change it to any number and still be able to send back on the channel of my choice.
Abdiel #55
Posted 13 March 2013 - 02:29 PM
The old rednet API used to be able to give you the ID of the computer which sent you a message. The modem API doesn't give you this by itself. If this is important for you, you can use the reply channel to transmit that. Otherwise, feel free to use it as an additional int value you can transmit for free.
Xenres #56
Posted 15 May 2013 - 01:04 AM
My question is, how many messages can traverse a single channel at the same time? I can imagine something like TCP/IP being implemented, wrapped like so – (packet[start_identifier][target_id][source_id][message_block][end_identifier]) The message block could be encoded for security, so that messages can only be read by target machine, or any machine where the hacker has figured out how to decrypt the packets he's intercepted. If only one message can go over the channel at a time, which does make sense, I'd imagine some sort of token ring structure, where every computer has to wait its turn to transmit on that channel. By having 128 channels available, you could use multiple channels, and just send on whichever channel you have an open send ability. I don't want to go into the logistics of it, but I'll be doing some sort of experiment in single player mode. I really think we need some sort of networking stack to take advantage of this, and then you could build services that utilize it. I'm going to try and come up with some proof of concept code, as I don't think I'm explaining myself very well.
Geforce Fan #57
Posted 17 May 2013 - 07:24 PM
Can you PM people within channels?
Also, I'm trying to sniff on channel 0, which is the channel for private rednet messages right?
I can't seem to see it. (No, I'm not sniffing other people's messages, just testing the security of my own)
Bubba #58
Posted 17 May 2013 - 09:27 PM
Can you PM people within channels?
Also, I'm trying to sniff on channel 0, which is the channel for private rednet messages right?
I can't seem to see it. (No, I'm not sniffing other people's messages, just testing the security of my own)

You could write a program that simulates a PM using encryption, but it won't actually be private due to the fact that there is no such thing as private messages anymore. The rednet api will use the ID of the computer that sends the message as the second argument of transmit, but it sends messages on the channel that you specify with rednet.send([channel], message).

Now broadcast messages use channel 65535, if that is what you are referring to.
BigSHinyToys #59
Posted 17 May 2013 - 10:23 PM
Can you PM people within channels?
Also, I'm trying to sniff on channel 0, which is the channel for private rednet messages right?
I can't seem to see it. (No, I'm not sniffing other people's messages, just testing the security of my own)

The Old rednet was a java level system that was secure. The new rednet (api) is a protocol built on peripheral calls to modem peripherals and is not secure. This is basically how it all works now.

Broadcast messages are all on CH: 65535

First rednet Opens out receive channel witch is out ID example our computer is 5
local modem = peripheral.wrap("left")
modem.open(os.getComputerID()) – this will get Out ID

when I rednet.send(7,"hello world!") the api dose this modem.transmit(7,5,"Hello world!")
remembering modem.transmit(<CH>,<CH to reply on>,<payload / message>)

The receiving computer is 7 and has opened its ID as well. That means it will now get that message on channel 7 this computer will output the event "rednet_message",5,"hello world!",8 <8 is the distance in meters> that is how we know what computer sent to us . Now this is where it gets interesting. We can directly control the modem and spoof fake ID's or use one channel for sending and receiving.

broadcasts are always on CH: 65535 so the api also opens this channel for receiving. When we do rednet.broadcast("Hello World") the api dose modem.transmit(65535,5,"Hello world!") so we still see a sender ID.

If people are using the old rednet protocols to listen in all you need to do it open the channel that is there ID and you can monitor all traffic. you will have to peripheral.wrap() it your self and open the channels manually also you will be looking at "modem_message" not "rednet_messages" they are slightly different in that they tell is the channel that was sen on as well as the channel the sender wants us to reply to
<"modem_message">, <side message received on eg "back">, <CH send on eg: 7>,
<CH preferred reply channel eg:5>, <payload/message eg: "hello world!">, <distance in meaters eg:8>
makerimages #60
Posted 30 July 2013 - 04:47 AM
Opening channels:
Opening channels is simple. All you have to do is…

local desiredChannel = 1
modem.open(desiredChannel)
But what does opening a channel mean exactly? Well, until you've opened a channel you cannot receive any messages on that channel. You can send messages though, so if all you need to do is send a bunch of messages then there is no need to open a channel.
Note: You can open 128 channels at any given time and receive messages on them.
Note 2: The largest channel you can open is 65535

Does the 128 channel limitation apply for a specific modem, a specific computer or the entire world?
theoriginalbit #61
Posted 30 July 2013 - 05:33 AM
Does the 128 channel limitation apply for a specific modem, a specific computer or the entire world?
Per modem. So if you have a computer with all 6 sides as modems you can have 768 channels open at any given point in time.
makerimages #62
Posted 30 July 2013 - 05:43 AM
ok, thanks
Edit: a few pages back, there was a piece of code to listen on all open channels, i implemented that into this program:

term.clear()
local modem=peripheral.wrap("left")
local SiteLookup={}
local function listen()
  while true do
	    local evts = {os.pullEvent()}
	    if evts[1] == "timer" then
		   return
	    elseif evts[1] == "modem_message" then
		   print("Message: "..evts[4])
	    end
  end
end
local max = 65535
local large = 128
while true do
for i=1, max, large do
  for x=i, i+large do
	    modem.open(x)
  end
	    os.startTimer(2) --Listen for two seconds and then move on to the next range
	    listen()
  for x=1, i+large do
	    modem.close(x)
  end
end
end

it says that on line 21 ( the line with modem.open(x) ) there are too many open channels. how do I fix this?
Bubba #63
Posted 30 July 2013 - 09:29 AM
-snip-

Look at your closing for loop:
  
for x=1, i+large do
   modem.close(x)
end

x=1 should be x=i
jesusthekiller #64
Posted 30 July 2013 - 10:38 AM
Just stumbled across this post, really nice tutorial :)/>
makerimages #65
Posted 31 July 2013 - 04:45 AM
-snip-

Look at your closing for loop:
  
for x=1, i+large do
   modem.close(x)
end

x=1 should be x=i

that fixed nothing


term.clear()
local modem=peripheral.wrap("left")
local SiteLookup={}
local function listen()
  while true do
	    local evts = {os.pullEvent()}
	    if evts[1] == "timer" then
		   return
	    elseif evts[1] == "modem_message" then
		   print("Message: "..evts[4])
	    end
  end
end
local max = 65535
local large = 128
while true do
for i=1, max, large do
  for x=i, i+large do
	    modem.open(x)
  end
	    os.startTimer(2) --Listen for two seconds and then move on to the next range
	    listen()
  for x=i, i+large do
	    modem.close(x)
  end
end
end

same error (too many open channels) same line(modem.open(x))
Bubba #66
Posted 31 July 2013 - 09:03 AM
same error (too many open channels) same line(modem.open(x))

Oops sorry. You should leave the correction there as it is a performance improvement, but it's not the issue. The issue is that you're adding i+large, which would actually be 129 channels instead of 128. Change it instead to i+large-1
tuocuggino #67
Posted 13 August 2013 - 03:12 PM
hi guys,
i'm not able to understand where where is the error on this programs:

turtle with a gate reader:

modem = peripheral.wrap("right")
m = peripheral.wrap("left")
while true do
	    data = m.get()
	    modem.transmit(1,2,data)
	    count = 0
	    for i in pairs(data) do
			    if i ~= nil then
					    count = count + 1
			    end
	    end
	    print(count)
end

Computer:

modem = peripheral.wrap("top")
modem.open(1)
local event, modemSide, senderChannel, replyChannel,
message, senderDistance = os.pullEvent("modem_message")
for i,v in pairs(message) do
    print(i..":"..tostring(v))
end

the computer give me a error, it say something like " the variabile message must be a table"
PsychicMiner2025 #68
Posted 21 April 2016 - 06:27 AM
Wow… Code for snooping on all channels…

modem = peripheral.wrap(modemside)
for i=0, 65535 do – Or how ever many channels there are
modem.open(i)
end

Would this allow you to snoop on rednet.send messages?

Edit: Wait.. can you only listen on 1 channel?

You could have a huge array of computers with wireless modems, all connected by network cables to a drive. Then you could set each computer (even thought it would take a while) to listen on different channels, each listening to 128 channels. e.g. computer 1, 1-128, computer 2, 129-256 ect. Then when a modem receives a message it would write the send and reply channels, the modem side and dist and message and write it to a file on the networked disk drive. not very practical in survival mode since you would need about 12131 stone 1112 redstone 512 ender pearls or 32 stacks! 512 glass panes and around 135 hours of smelting the stone (in one furnace) so dont attempt in survival mode. im sure there's easier ways to do this and since wireless modems only have a max range of 381 blocks at max altitude this would only get a very small scan range but would be good in a populated area in a server. you always could have less or even one modem that is quickly switching between groups of channels but then theres the chance you could miss a message. you could build a box made of computers reducing the wire needs and decreasing the chance that a signal or a low channel that is only in range of the high channel end of a line gets missed. anyway because of the 256 max range of wires you would have to put computers on both sides of a half length wire if you made a long line. sorry for the long post. also this is my first post. far from a "hi i'm new"











and one floppy disk ;)/>
valithor #69
Posted 23 April 2016 - 02:12 AM
-snip

This is actually something that I have seen a few times on servers. The one improvement you can make to the system you described is having 5 wireless modems per computer instead of 1 (can open 128 channels per modem not computer), and 1 wired modem to connect to the drive. This would cut down on the costs.

edit:

Also welcome to the forums :D/>
Edited on 23 April 2016 - 12:12 AM
MineRobber___T #70
Posted 13 November 2016 - 03:03 AM
I did some math. Guess how many modems you need in order to scan all channels at once?

The answer: 534.

My explanation:

SpoilerIn order to figure out how many computers you need to monitor all of the possible channels, you would use:


math.ceil(x/(y*z))

where x = the number of channels (65535), y = how many channels a modem can monitor (128), and z = how many modems you can connect to a computer (6).

As such, the number of computers you need ("math.ceil(65535/(128*6))") is 86.

However, this game me a thought. What if you networked a bunch of modems together? Say, for example, you could use a bunch of modems hooked onto a networking cable hooked into a wired modem hooked into one side of the computer. (you can't, by the way.) Well, then the equation becomes:


math.ceil(x/(y*(z*a)))

where x = the number of channels (65535), y = how many channels a modem can monitor (128), z = how many wired modems you can connect to a computer (6), a = how many wireless modems are on the networking cable (variable), and we want the result to be 1.

After plugging in as many variables as I could, I came up with a = 89. That means 89 modems on EACH network cable. Hey, I didn't say this would be space-efficient. Isolating the "(z*a)" from the equation, ("(6*89)" by the way) that solves to 534.

Resources you would need:
Spoiler(if using wireless modem, 4872, otherwise, 600, add 8 if using normal computer) stone,
138 redstone,
534 enderpearls,
(if using ender modems, 4272, otherwise, 0, add 8 if using advanced computer) gold