Jump to content




Sending bits over modem

networking api peripheral

4 replies to this topic

#1 cmdpwnd

  • Members
  • 128 posts
  • LocationHere

Posted 24 June 2015 - 05:41 AM

When sending data, it is sent as a string in rednet. Firstly, does this not apply when sending soley from the modem instead of via rednet? Second if no, is it still possible to send bits of data without it being interpreted as a byte?

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 June 2015 - 06:09 AM

Lua offers a limited selection of types compared to most other languages; strings, numbers, booleans, tables, functions, coroutines, and nil. Per the wiki, you can send any of these types directly via modems, with the exception of functions and coroutines (which get translated to nil). (Though to be fair, that was only documented there a bit over a week ago.)

So yeah, if you specifically want to send bools, just send bools.

modem.transmit(targetChannel, suggestedReplyChannel, true)

Edit:

It's important to note that modem messages arrive as events on the eligible destination systems. Events are pulled from the front of the event queue (each time a system yields by eg calling os.pullEvent()), and new events are added to the end. Each such system can only handle up to 256 events in their queue at a time. That means that if you're sending data one bit per message, there is an absolute upper limit of just 32 bytes before you either allow the target system to start pulling events, or before you start losing data - and odds are the "in practise" figure will be lower, because the modem_message events aren't going to be the only ones populating the queue.

Likewise, if you eg transmit two messages for every one that's getting pulled, the queue will quickly overflow and you'll start losing information.

Edited by Bomb Bloke, 24 June 2015 - 06:19 AM.


#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,451 posts

Posted 24 June 2015 - 06:18 AM

And you can send all of those types through the rednet API functions just as well as you can via the raw modem peripheral function.

#4 cmdpwnd

  • Members
  • 128 posts
  • LocationHere

Posted 24 June 2015 - 06:37 PM

ok, but the bool value `true` while specifies a state is still 4bytes long, so in the event that I send `true` is it sent as 4bytes or if not, what is it sent as and how long is it?

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,451 posts

Posted 24 June 2015 - 06:56 PM

It doesn't matter. All of those details are abstracted away on the Java side of things. A Boolean will send and be received just as fast as a ten kilobyte string, or a large table.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users