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

Disknet: "Modem" communications through a disk drive!

Started by LDDestroier, 02 May 2019 - 01:58 PM
LDDestroier #1
Posted 02 May 2019 - 03:58 PM
Want to have modemless interdimensional communication, but Skynet is too slow? (it's not that slow)

Are you on a version of ComputerCraft that doesn't support websockets? (update, you luddite)

Or are you that guy?

Then Might I IntroDuce To You


DISKNET


The Only Network API That You Can Download By Executing The Command:


wget https://github.com/LDDestroier/CC/raw/master/disknet.lua

Disknet works by using a shared directory between two or more computers to emulate the functionality of a modem.

You open a "channel" file, then can send/receive messages to/from it.

While one machine is receiving, it is constantly checking the channel file for changes. If it finds one, it will re-read it and see if a new message was sent.

This reads one or more files every tick, so using several channels might slow it down a tad.


This might not seem useful, but if you have two duplicated floppy disks with the same ID, you can use this for private inter-dimensional communications!

Without that, you can also essentially double the maximum possible length of wired cables from 256 to 512 by sticking a disk drive w/ a disk at the halfway point. That's useful, probably.


I've always wanted to make something like this since 2014, but never knew how until now!


Here's the list of functions and their uses:
SpoilerSet the path that Disknet uses. It should really be on a disk, though.

disknet.mainPath = "disk/DISKNET" -- this is the default

Open a channel for use. You can NOT use unopened channels.

success = disknet.open(channel) -- Can be any number or string

Closes a channel. / Closes all channels.

success = disknet.close(channel) -- closes ONE channel
success = disknet.closeAll() -- closes EVERY channel

Checks if a channel is opened.

isOpen = disknet.isOpen(channel)

Sends a message. Can't send functions or any other datatypes that cannot be serialized. Can optionally specify a recipient by computer ID.

success = disknet.send(channel, message, [recipient ID])

Receives a message. Can optionally filter with channel (assuming said channel is open) or by the sender's ID.

message, channel, senderID, timeThatMessageWasSentAt = disknet.receive(channelFilter, [sender ID])

Tell me what you think in the comments, or I'll eat your shoes
Edited on 08 May 2019 - 07:32 PM
SquidDev #2
Posted 02 May 2019 - 04:07 PM

while true do
  -- ...
  os.queueEvent("")
  os.pullEvent("")
end

I realise this is the only way to do it, but "oh no" none-the-less.
LDDestroier #3
Posted 02 May 2019 - 05:39 PM

while true do
  -- ...
  os.queueEvent("")
  os.pullEvent("")
end

I realise this is the only way to do it, but "oh no" none-the-less.

That's a fair analysis. I tried to reduce the amount of new fs.open() calls as best I could, but it's always going to be hard on the hard drive.
SquidDev #4
Posted 02 May 2019 - 05:54 PM
I tried to reduce the amount of new fs.open() calls as best I could, but it's always going to be hard on the hard drive.
If you wanted to be really fancy, you could open them in binary mode and then seek to the beginning of the file.

Though then I guess this wouldn't work on anything but CC:T, which rather defeats the "Are you on a version of ComputerCraft that doesn't support websockets?". Ptth, who are these people?
LDDestroier #5
Posted 02 May 2019 - 05:56 PM
If you wanted to be really fancy, you could open them in binary mode and then seek to the beginning of the file.

Though then I guess this wouldn't work on anything but CC:T, which rather defeats the "Are you on a version of ComputerCraft that doesn't support websockets?". Ptth, who are these people?

Troglodytes (or anyone using a technic pack that is restricted to an older version of minecraft to maintain compatibility with the rest of the mods), that's who!
Bomb Bloke #6
Posted 03 May 2019 - 08:09 AM
I realise this is the only way to do it

Is it really? I mean, even regular modem messages don't arrive until the next server tick. Obviously this can go faster, but does it need to?
SquidDev #7
Posted 03 May 2019 - 11:26 AM
Is it really? I mean, even regular modem messages don't arrive until the next server tick. Obviously this can go faster, but does it need to?
IIRC wireless modem messages are instant, but I can't think of any programs which actually need same-tick delivery. Would probably be better to use sleep(0) by default (still kinda eww), and then allow using queue/yield if a config option is set.