Jump to content




[v0.1 - Beta] disknet


  • You cannot reply to this topic
43 replies to this topic

#1 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 04 August 2014 - 09:21 PM

http://pastebin.com/bYc0XzLg

This program was inspired by someone requesting a "disk inter-world chat" program, and thus I've created a rednet-like api that uses disks. It is still in beta, and I am mostly posting this so people can find the bugs and give me ideas. One thing I want to figure out is, how could I keep the disk from being filled up? Is this even an issue? Other than that, ease of use comes to mind.

documentation:

- disknet.open( side, file ) --#returns an ID relating to the file
- disknet.receive( [file, [timeout, [ side ] ] ] ) --#returns the sent data
- disknet.isOpen( side ) --#returns boolean
- disknet.send( message, side, ID ) --#sends message
- disknet.broadcast( message ) --#calls send on every open file & side

Any questions will be answered comprehensively if possible. Be aware I have not extensively tested this, since I need to actually open minecraft to do so.

Edited by KingofGamesYami, 04 August 2014 - 09:21 PM.


#2 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 06 August 2014 - 05:44 AM

Little newbie question, how do i install it correctly? Got it working, gimme a sec.

The program will not run as it doesn't realize that i've opened the disknet side correctly when i disknet.send() and using disknet.isOpen() returns true.

I fixed that by removing lines 34 and 35, and got it to write into a file IF there's a table in it already, which means you need to make it have a first time input. Currently though the receive is not working correctly as i can see that my messages are being saved and reviewing the code i guess maybe it's not actually creating a disknet event?

Actually i don't think that the file transfer between 2 floppies works. (i got it to work if i used creative mode middle click to copy the floppy, however just grabbing 2 floppies and labeling them the same doesnt't work.)

Edited by Dragon53535, 06 August 2014 - 06:29 AM.


#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 06 August 2014 - 10:03 PM

It should. Floppies named identically should be exactly the same.

Topic of disknet send, here's how I think it should work:
local id = disknet.open( "top", "chat" )
disknet.send( "Hello", "top", id ) --#note you NEED both "top" and id

To recieve:
local id = disknet.open( "top", "chat" )
local event, side, file, message = disknet.receive()

Test this out and see if it still works. As with rednet, the receiver must be open FIRST.

Edit: I think I found the bug, part of the code had differently named variables by accident. Updated pastebin

Here's the bit that makes the events:
Spoiler

Edited by KingofGamesYami, 07 August 2014 - 05:25 AM.


#4 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 07 August 2014 - 10:20 PM

It still does not like making the file the first time. My fault there again, it doesn't like the file existing but nothing in it :P HOWEVER the disknet_message doesn't get new messages and your syntax is off, where you put message on the disknet.receive is getting the label on the computer.

Edited by Dragon53535, 08 August 2014 - 02:25 AM.


#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 08 August 2014 - 03:23 AM

View PostDragon53535, on 07 August 2014 - 10:20 PM, said:

It still does not like making the file the first time. My fault there again, it doesn't like the file existing but nothing in it :P HOWEVER the disknet_message doesn't get new messages and your syntax is off, where you put message on the disknet.receive is getting the label on the computer.
I've updated the pastebin since writing that post, you are correct. Also, testing myself on CC 1.63 it appears named floppies do not have the same files. Oh well...

#6 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 17 September 2014 - 11:43 PM

Do you think that you could make routers, which are seperate computers that have disk drives that take in rednet information, send it through disknet, then broadcast it back to rednet?
A computer could use a rednet chatroom, which would send the chatting over rednet to the router, then, over disknet, to another router, then to the computer.
Then the same thing the other way around.

Basically, worldwide rednet.

It would be better because you wouldn't have to rewrite programs to use disknet, and 1 router would work with many computers at once. Even pocket computers could use routers!
Oh, and the computers won't need a special client either, because it's:
[computer] -rednet--> [router] -disknet--> [router] -rednet--> [computer]

Work on that please. Like, now.

#7 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 September 2014 - 02:27 AM

This does not work. I mistakenly thought it would, and after testing realized it would not... Also there is a function called 'redRepeat', which is my attempt to do what you just said.

#8 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 18 September 2014 - 02:10 PM

View PostKingofGamesYami, on 18 September 2014 - 02:27 AM, said:

This does not work. I mistakenly thought it would, and after testing realized it would not... Also there is a function called 'redRepeat', which is my attempt to do what you just said.

I had tested it too with the 1.7.10 beta, and I thought it worked. I had two duplicate floppies with nothing on them, put a file on one of them, then checked the other one, which then had that file with its contents. Please try it assuming disks do that.

#9 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 September 2014 - 02:16 PM

View PostLDDestroier, on 18 September 2014 - 02:10 PM, said:

View PostKingofGamesYami, on 18 September 2014 - 02:27 AM, said:

This does not work. I mistakenly thought it would, and after testing realized it would not... Also there is a function called 'redRepeat', which is my attempt to do what you just said.

I had tested it too with the 1.7.10 beta, and I thought it worked. I had two duplicate floppies with nothing on them, put a file on one of them, then checked the other one, which then had that file with its contents. Please try it assuming disks do that.
Yes, it works if you have litterally duplicated floppies, however this was made to work with named floppies, since how would you get identical floppies without cheating?

#10 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 18 September 2014 - 03:20 PM

View PostKingofGamesYami, on 18 September 2014 - 02:16 PM, said:

View PostLDDestroier, on 18 September 2014 - 02:10 PM, said:

View PostKingofGamesYami, on 18 September 2014 - 02:27 AM, said:

This does not work. I mistakenly thought it would, and after testing realized it would not... Also there is a function called 'redRepeat', which is my attempt to do what you just said.

I had tested it too with the 1.7.10 beta, and I thought it worked. I had two duplicate floppies with nothing on them, put a file on one of them, then checked the other one, which then had that file with its contents. Please try it assuming disks do that.
Yes, it works if you have litterally duplicated floppies, however this was made to work with named floppies, since how would you get identical floppies without cheating?

They could be distributed in a server by admins. If someone is abusing the disknet, his disk is taken.

Edited by LDDestroier, 18 September 2014 - 03:20 PM.


#11 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 18 September 2014 - 07:36 PM

Could you better explain the syntax and functions of the disknet api? I need some example programs and explanations as to what goes on.

#12 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 September 2014 - 07:57 PM

- disknet.open( side, file ) --#returns an ID relating to the file
- disknet.receive( [file, [timeout, [ side ] ] ] ) --#returns the sent data
- disknet.isOpen( side ) --#returns boolean
- disknet.send( message, side, ID ) --#sends message
- disknet.broadcast( message ) --#calls send on every open file & side

os.loadAPI( "disknet" )
local id = disknet.open( "right", "chat" )
disknet.send( "hello", "right", id )
local event, side, file, message = disknet.receive()
print( "recieved " .. message .. " on side " .. side .. " in file " .. file "!" )


#13 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 18 September 2014 - 08:01 PM

View PostKingofGamesYami, on 18 September 2014 - 07:57 PM, said:

- disknet.open( side, file ) --#returns an ID relating to the file
- disknet.receive( [file, [timeout, [ side ] ] ] ) --#returns the sent data
- disknet.isOpen( side ) --#returns boolean
- disknet.send( message, side, ID ) --#sends message
- disknet.broadcast( message ) --#calls send on every open file & side

os.loadAPI( "disknet" )
local id = disknet.open( "right", "chat" )
disknet.send( "hello", "right", id )
local event, side, file, message = disknet.receive()
print( "recieved " .. message .. " on side " .. side .. " in file " .. file "!" )
I'd like something more detailed than that. What does opening an ID do? Does it put data on the disk that the computer with that ID only can read? Do I use disknet.receive just like rednet.receive? What do I do exactly to load the api (put pastebin file on it with the name disknet then do command?)? Examples?

#14 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 September 2014 - 11:35 PM

You do not "open an id." You open a file on a side. "id" is simply a variable that holds a key to a table within the api, that contains the settings for that id.

disknet.receive is designed to work exactly like rednet.receive, except the outputs are modified (as you can see with my variables)

Load the api just like every other api...

>pastebin get bYc0XzLg disknet
os.loadAPI( "disknet" )

Edit: if you need more information, just look at the code... it's really not very complicated.

Edited by KingofGamesYami, 18 September 2014 - 11:35 PM.


#15 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 23 September 2014 - 07:06 PM

Well I don't know how to program well, if at all. Could you try just making a router program? It takes rednet info and broadcasts it on disknet, and takes disknet data (if it wasn't the message you broadcasted) and broadcasts it on rednet. Same with just to ids. Seems simple enough, but I suck at LUA, so please do that and I will put it on a server and cite you a lot.

#16 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 23 September 2014 - 09:19 PM

I tried disknet.send with the API loaded, but it told me that it had an invalid id. Here's what I put:

diskcast:2: Invalid disknet id

Diskcast is the thing I did to test sending data to a receiving disknet thing, that has the code:

disknet.open("right", "chat")
while true do
id, a = disknet.receive()
write(a)
end

All the receiver does is unlabel the floppy disk (back to "Floppy Disk") and do nothing else.

I need help with both of these. If I knew what the id was or what the event should be, then I might be able to fix it myself.

#17 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 23 September 2014 - 10:40 PM

function receive( pFilter, nTimeout, _side, _sender )
        local id
        if nTimeout and type( nTimeout ) ~= "number" then
                error( "Expected string, number[, string], got " .. type( pFilter ) .. ", " .. type( nTimeout ) .. "," .. type( _side ), 2 )
        elseif pFilter and type( pFilter ) ~= "string" then
                error( "Expected string, number[, string], got " .. type( pFilter ) .. ", " .. type( nTimeout ) .. "," .. type( _side ), 2 )
        elseif _side and type( _side ) ~= "string" then
                error( "Expected string, number[, string], got " .. type( pFilter ) .. ", " .. type( nTimeout ) .. "," .. type( _side ), 2 )
        end
        if nTimeout then
                id = os.startTimer( nTimeout )
        end
        while true do
                local event = { os.pullEvent() }
                if event[ 1 ] == "disknet_message" then
                        if event[ 2 ] == _side or not _side then
                                if event[ 3 ] == pFilter or not pFilter then
                                        return unpack( event )
                                end
                        end
                elseif event[ 1 ] == "timer" and event[ 2 ] == id then
                        return nil
                end
        end
end


#18 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 26 September 2014 - 08:35 PM

View PostKingofGamesYami, on 23 September 2014 - 10:40 PM, said:

function receive( pFilter, nTimeout, _side, _sender )
		local id
		if nTimeout and type( nTimeout ) ~= "number" then
				error( "Expected string, number[, string], got " .. type( pFilter ) .. ", " .. type( nTimeout ) .. "," .. type( _side ), 2 )
		elseif pFilter and type( pFilter ) ~= "string" then
				error( "Expected string, number[, string], got " .. type( pFilter ) .. ", " .. type( nTimeout ) .. "," .. type( _side ), 2 )
		elseif _side and type( _side ) ~= "string" then
				error( "Expected string, number[, string], got " .. type( pFilter ) .. ", " .. type( nTimeout ) .. "," .. type( _side ), 2 )
		end
		if nTimeout then
				id = os.startTimer( nTimeout )
		end
		while true do
				local event = { os.pullEvent() }
				if event[ 1 ] == "disknet_message" then
						if event[ 2 ] == _side or not _side then
								if event[ 3 ] == pFilter or not pFilter then
										return unpack( event )
								end
						end
				elseif event[ 1 ] == "timer" and event[ 2 ] == id then
						return nil
				end
		end
end

What is the 'sender' and 'pFilter' things when setting the function, and their syntax? I'm lost when I look at the code.
Also, the thing I do see is that there is a 'while true do' loop in receive(). Does that mean that it the function will go on forever, or am I not looking deep enough and it ends when the timeout ends?

Edited by LDDestroier, 26 September 2014 - 08:37 PM.


#19 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 26 September 2014 - 09:06 PM

View PostLDDestroier, on 26 September 2014 - 08:35 PM, said:

What is the 'sender' and 'pFilter' things when setting the function, and their syntax? I'm lost when I look at the code.
Also, the thing I do see is that there is a 'while true do' loop in receive(). Does that mean that it the function will go on forever, or am I not looking deep enough and it ends when the timeout ends?
The function would go on forever, except I have two cases in which it returns. 1) If the timer runs out or 2) when it receives a message. In the case of the former, it will return nil.

It looks like _sender was going to added and never was. It does nothing in that section of code.

pFilter is basically just that, a filter... It is similar to the rednet protocol.

Edited by KingofGamesYami, 26 September 2014 - 09:07 PM.


#20 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 29 September 2014 - 08:02 PM

View PostKingofGamesYami, on 26 September 2014 - 09:06 PM, said:

View PostLDDestroier, on 26 September 2014 - 08:35 PM, said:

What is the 'sender' and 'pFilter' things when setting the function, and their syntax? I'm lost when I look at the code.
Also, the thing I do see is that there is a 'while true do' loop in receive(). Does that mean that it the function will go on forever, or am I not looking deep enough and it ends when the timeout ends?
The function would go on forever, except I have two cases in which it returns. 1) If the timer runs out or 2) when it receives a message. In the case of the former, it will return nil.

It looks like _sender was going to added and never was. It does nothing in that section of code.

pFilter is basically just that, a filter... It is similar to the rednet protocol.

So can I simply not put the pFilter thing if I want it to see everything? And simply ignore sender?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users