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

Unique namespace for broadcasts?

Started by OminousPenguin, 19 April 2012 - 12:46 AM
OminousPenguin #1
Posted 19 April 2012 - 02:46 AM
Hi all.
I was wondering what people think about the practice of using a unique namespace for broadcast messages to avoid clashes with other programs and whether this should be encouraged.

For example, you want to broadcast a message "activate" to all other computers running your program. Instead of broadcasting "activate", you broadcast "email@example.com#activate" or something like that.

By doing this, and having your program ignore any received messages without your namespace prefix, you avoid any problems if for example another unrelated program broadcasts "activate" for it's own purposes.

So, good idea to encourage this? You do it already? Have a better idea? Discuss.
coolblockj #2
Posted 19 April 2012 - 02:57 AM
Why not just have a specific keyword with "activate"? Thats what i do for these types of things.
cant_delete_account #3
Posted 19 April 2012 - 03:19 AM
Hi all.
I was wondering what people think about the practice of using a unique namespace for broadcast messages to avoid clashes with other programs and whether this should be encouraged.

For example, you want to broadcast a message "activate" to all other computers running your program. Instead of broadcasting "activate", you broadcast "email@example.com#activate" or something like that.

By doing this, and having your program ignore any received messages without your namespace prefix, you avoid any problems if for example another unrelated program broadcasts "activate" for it's own purposes.

So, good idea to encourage this? You do it already? Have a better idea? Discuss.
I use something at the start of my broadcast like 'forthesbrosprogram:MESSAGEHERE', then on my receiver, I use string.sub(msg, etc, etc) where msg is the second rednet.receive variable. So it checks for 'forthesbrosprogram:', and if it has that, it reads the message after the : and does whatever it needs to do with it, like check for certain messages, etc.
BigSHinyToys #4
Posted 19 April 2012 - 10:36 AM
I don't use broadcast so messages only go to where they are needed. and I don't have to worry about that kind of problem. as part of my routing network i do use 7 letter codes to denote Instructions from node to node. e.g. REG_NOD makes the computer register the nodes ID or INSTAL makes the computer automatically update its version of node.
I use a simple code for this. this is an example not the real code.
Spoiler

while true do
e,e1,e2 = os.pullEvent()
if e == "REDNETMESSAGE" then
  local temp = string.sub(e2,1,7)
  if temp == "REG_NOD" then
   --function here--
   end
end
end
OminousPenguin #5
Posted 19 April 2012 - 01:45 PM
Why not just have a specific keyword with "activate"? Thats what i do for these types of things.

What kind of keyword? Does it uniquely identify your program or could someone else also use it unintentionally?

I use something at the start of my broadcast like 'forthesbrosprogram:MESSAGEHERE', then on my receiver, I use string.sub(msg, etc, etc) where msg is the second rednet.receive variable. So it checks for 'forthesbrosprogram:', and if it has that, it reads the message after the : and does whatever it needs to do with it, like check for certain messages, etc.

Yeah I've done OminousPenguin<pid>v<version>#<message>
Where <pid> is an integer identifying the program and <version> is an integer identifying the program. And for my message I use integer codes.
So for example one of my messages looks like this: OminousPenguin1v1#1

Including the version enables controlling compatibility between versions.

I don't use broadcast so messages only go to where they are needed. and I don't have to worry about that kind of problem. as part of my routing network i do use 7 letter codes to denote Instructions from node to node. e.g. REG_NOD makes the computer register the nodes ID or INSTAL makes the computer automatically update its version of node.
I use a simple code for this. this is an example not the real code.

If you don't broadcast then it's probably not so much of an issue, however, for novice users using downloaded code, there is still the possibility of multiple programs on the same computer reacting to messages not intended for them.

Another program could use the code 'REG_NOD' as well. The idea of the unique namespace like the email address or CC username is that you're never going to get another program using the same one (unless intentionally).
Leo Verto #6
Posted 21 April 2012 - 11:08 AM
I really need this kind of receiver for project netblock, since we're about to have a lot of rednet traffic.
But namespaces are easier to use for us.
BigSHinyToys #7
Posted 21 April 2012 - 09:33 PM
I really need this kind of receiver for project netblock, since we're about to have a lot of rednet traffic.
But namespaces are easier to use for us.

you just need to make a sort of IP and have all packets using netblock conform to the same basic rule. that would allow a computer to decide quickly whether to action or discard a received packet. something like example.

NetBlock=12>28=100=messagehere

where NetBlock is defining it as a project net block packet.
12 is the ID of sender
28 is id of reciver
100 is port number
messagehere is the continence of the packet.

with a simple check you could determine viability.you would make a function that splits this packet into its parts checks if they are correct. and returns them as a table or strings.

e.g
tab[1] true – this is a correct packet)
tab[2] 12 – sender ID
tab[3] 28 – reviver
tab[4] 100 – port.


There is relay no need of a separate var to be sent.

Option two make your own os.pullEvent() and build in the above system making it return a already filtered message.
so the reviced message would be NetBlock=12>28=100=messagehere but it would return it brocken down into sections (If you need help with this i may be of assistance given i use this Method in GP-IS)
eg

e,e1,e2,e3,e4,e5 = os.pullEventNetBlock()

would return

e NetBlock
e1 12
e2 18
e3 messagehere
e4 50
Leo Verto #8
Posted 21 April 2012 - 09:56 PM
I really need this kind of receiver for project netblock, since we're about to have a lot of rednet traffic.
But namespaces are easier to use for us.

you just need to make a sort of IP and have all packets using netblock conform to the same basic rule. that would allow a computer to decide quickly whether to action or discard a received packet. something like example.

NetBlock=12>28=100=messagehere

where NetBlock is defining it as a project net block packet.
12 is the ID of sender
28 is id of reciver
100 is port number
messagehere is the continence of the packet.

with a simple check you could determine viability.you would make a function that splits this packet into its parts checks if they are correct. and returns them as a table or strings.

e.g
tab[1] true – this is a correct packet)
tab[2] 12 – sender ID
tab[3] 28 – reviver
tab[4] 100 – port.


There is relay no need of a separate var to be sent.

Option two make your own os.pullEvent() and build in the above system making it return a already filtered message.
so the reviced message would be NetBlock=12>28=100=messagehere but it would return it brocken down into sections (If you need help with this i may be of assistance given i use this Method in GP-IS)
eg

e,e1,e2,e3,e4,e5 = os.pullEventNetBlock()

would return

e NetBlock
e1 12
e2 18
e3 messagehere
e4 50
Wow thank you for your help!
This can be really helpful, especially the idea of using ports!