Jump to content




iNet - Powerful & Simple Networking


12 replies to this topic

#1 KingofGamesYami

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

Posted 08 August 2014 - 09:49 PM

API Functions (accessible through iNet.* )

local object = iNet.open( number channel, number replyChannel, string side )

Creates and returns an iNet object.

local tbl = { iNet.waitForAny( object iNet Object, ... ) }

Waits for any of the object to receive a message, and returns the message values.

local tbl = { iNet.waitForAll( object iNet Object, ... ) }

Waits for all objects to receive a message, and returns message values.

Object Functions (accessible through object:* )

object:send( string/table message )

Sends a message

local message, distance, sender = object:receive()

Receives messages. Sender is the computer label, if available, or the computer ID.

object:reply( message )

Sends a message to the computer that last communicated with the object.

object:repeat()

Repeater program. Duh.

object:setProctal( string proctal )

Sets the proctal filter. This will automatically be applied to send and receive. In 1.2, the spelling was updated to object:setProtocol

object:setEncryption( function encrypt )

An advanced setting for encrypting messages. The function specified will be given string message. Automatically encrypts object:send.

object:setDecryption( function decrypt )

The counterpart to object:setEncryption. This will automatically decrypt received messages.

object:removeEncryption()

Removes the encryption filter (if any)

object:removeDecryption()

Removes the decryption filter (if any)

object:sendFile( string fileName )

Sends a file. Be aware that some files may be corrupted when sent through the event filter. object:receive() will recognise it as a file and save it as the filename specified. If this overwrites something you had, well too bad for you. It will also return the filename, instead of the fileData. In 1.2, this should no longer be a concern, because all data is sent with base64 encoding

Downloads:

1.0 - pastebin get FWpbap6B
1.2 (beta) - pastebin get vuzF5t8p
--#sending script (run this SECOND)
os.loadAPI( "iNet" )
local channel = iNet.open( 255, 256, "top" )
channel:setProctal( "Examples" ) --#note: in 1.2, this was changed to channel:setProtocol( "Examples" )
channel:send( "Hello" )
local message, distance, sender = channel:receive()
print( "Recieved '" .. message .. "' from " .. sender .. ", " .. distance .. "m away" )
channel:reply( "Confirm" )
--#receiving script  (run this FIRST)
os.loadAPI( "iNet" )
local channel = iNet.open( 23, 255, "top" )
channel:setProctal( "Examples" ) --#see above note regarding this function and 1.2
local message, distance, sender = channel:receive()
print( "Recieved '" .. message .. "' from " .. sender .. ", " .. distance .. "m away" )
channel:send( "This will be ignored as it is on the wrong channel!" )
channel:reply( "Hello, " .. sender )
local message, distance, sender = channel:receive()
print( "Recieved '" .. message .. "' from " .. sender .. ", " .. distance .. "m away" )

Edited by KingofGamesYami, 21 August 2014 - 03:12 AM.


#2 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 09 August 2014 - 05:41 AM

Neat API!
Could you add a B64 converter to avoid event corruption?

Edited by skwerlman, 09 August 2014 - 05:41 AM.


#3 KingofGamesYami

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

Posted 10 August 2014 - 07:25 PM

You could set B64 as the encrypt/decryption yourself. Example:
os.loadAPI( "iNet" )
local channel = iNet.open( 255, 256, "top" )
local function enc(data) --#found on google
	return ((data:gsub('.', function(x)
		local r,b='',x:byte()
		for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
		return r;
	end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
		if (#x < 6) then return '' end
		local c=0
		for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
		return b:sub(c+1,c+1)
	end)..({ '', '==', '=' })[#data%3+1])
end
channel:setEncryption( enc )

--#and on recieving;
--#bla bla bla set up apis & such...

local function dec(data) --#also from google
	data = string.gsub(data, '[^'..b..'=]', '')
	return (data:gsub('.', function(x)
		if (x == '=') then return '' end
		local r,f='',(b:find(x)-1)
		for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
		return r;
	end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
		if (#x ~= 8) then return '' end
		local c=0
		for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
		return string.char(c)
	end))
end
channel:setDecryption( dec )

The B64 converter code I found here: http://lua-users.org...i/BaseSixtyFour

Edited by KingofGamesYami, 10 August 2014 - 07:25 PM.


#4 KingofGamesYami

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

Posted 14 August 2014 - 01:19 AM

*bump* (added poll)

#5 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 15 August 2014 - 11:02 AM

Regarding the poll: I think it should always convert, but also have an optional flag to prevent conversion if user so chooses.

#6 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 19 August 2014 - 07:12 AM

I like it, rednet always bugs me so I will look into this. Just on a side note, encrypt and decrypt should probably pass the iNet connection object as a second argument - so you can implement 'handshakes' or whatever (Read Diffie-Hellman).

To be totally pedantic: Is protocol not spelt with an o?

Edited by SquidDev, 21 August 2014 - 06:51 AM.


#7 KingofGamesYami

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

Posted 19 August 2014 - 12:22 PM

View PostSquidDev, on 19 August 2014 - 07:12 AM, said:

I like it, rednet always bugs me so I will look into this. Just on a side note, encrypt and decrypt should probably pass the iNet connection object as a second argument - so you can implement 'handshakes' or whatever (Read Diffie-Hellman).
I have no idea what you just said, but ok.

View PostSquidDev, on 19 August 2014 - 07:12 AM, said:

To be totaly pedantic: Is protocol not spelt with an o?
Yes, yes it is... *facepalm* I'll fix the code later.

#8 KingofGamesYami

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

Posted 19 August 2014 - 10:34 PM

iNet 1.2 (beta) released! I don't really have time to test it in game (since I don't have peripherals on the emulator I use), thus if you find any bugs/errors please post.

pastebin get vuzF5t8p

changelog

Edited by KingofGamesYami, 21 August 2014 - 03:13 AM.


#9 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 21 August 2014 - 02:13 AM

View PostSquidDev, on 19 August 2014 - 07:12 AM, said:

To be totaly pedantic: Is protocol not spelt with an o?
To be totally pedantic, is totally not spelt with two l's?

#10 KingofGamesYami

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

Posted 21 August 2014 - 03:14 AM

View Postskwerlman, on 21 August 2014 - 02:13 AM, said:

View PostSquidDev, on 19 August 2014 - 07:12 AM, said:

To be totaly pedantic: Is protocol not spelt with an o?
To be totally pedantic, is totally not spelt with two l's?
Argue with the official wiki: link

Edited by KingofGamesYami, 24 August 2014 - 12:01 AM.


#11 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 21 August 2014 - 06:51 AM

View Postskwerlman, on 21 August 2014 - 02:13 AM, said:

View PostSquidDev, on 19 August 2014 - 07:12 AM, said:

To be totally pedantic: Is protocol not spelt with an o?
To be totally pedantic, is totally not spelt with two l's?
I don't see anything wrong. :P

#12 DigitalMisha

  • Members
  • 9 posts

Posted 20 November 2014 - 03:25 PM

inet:153: Expected string
when running inet:open function. Why? My code is:
local channel = inet:open(255, 256, "top")


#13 KingofGamesYami

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

Posted 20 November 2014 - 04:04 PM

You are using incorrect syntax.

inet:open(255, 256, "top")
actually gives my code this:
inet.open( inet, 255, 256, "top" )

Instead of using the colin ( : ), use the period (.). the colin is reserved for object methods only.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users