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

Httpnet Instant Messages Over Http! No Peripherals Required

Started by PixelToast, 14 September 2013 - 11:06 AM
PixelToast #1
Posted 14 September 2013 - 01:06 PM
PSA: old and broken do not use




This is a functional CC API and server (not CC) that allows for instant communication over http using socket sorcery to handle requests

the server is completely written in Lua and requires just LuaSocket to function
Linux/Mac: try "apt-get install luarocks" if not then get it from http://www.luarocks.org/en/Download then do "luarocks install luasocket"
Windows: https://code.google..../luaforwindows/ has everything you need
if someone wants to attempt to make this in php please do, because people say it would be easier though from what i can tell by how php works this would be hard to do

Media:

_______________________________________________________________________________________________________________________________________________________________________________



(embed was derping)


Documentation:
_______________________________________________________________________________________________________________________________________________________________________________


local h=httpnet.new([host[,port[,id]]])
host is the IP of the server, defaults to "localhost"
port is the port, defaults to 1337
id is used in :send, it will also open the channel


event httpnet_message h.uid channel returnchannel data
like modem_message, see h.uid below


h:open(...)
will open all channels specified


h:close(...)
will close all channels specified


h:close()
will close all channels


h:transmit(chan,reurnchan,data)
like modem.transmit


h:send(chan,data)
will send data to chan, using the id specified in .new as the returnchan


h:get([timeout])
waits for the "httpnet_message" event and returns it


h.isOpen[chan]
tells you if chan is open, do not set directly, use :close and :open


h.uid
a secret random hex string, use to filter events


h:exit()
do this after you are done


h:loadplugin(path,...)
loads a plugin

Plugins

Spoiler
Client plugins

_______________________________________________________________________________________________________________________________________________________________________________



| HTTPNet client plugin |
required on the top of of each plugin to make sure it is not ran by anything other than httpnet


handle
the instance that called :loadplugin


name="foo"
specifies the name of the plugin, this must be the same name as the server plugin for them to communicate


function apievent(...)
called when the server plugin triggers an event


apicall(...)
calls the server plugin function


function unload(...)
called when the plugin gets unloaded

see example api
Server plugins

_______________________________________________________________________________________________________________________________________________________________________________


| HTTPNet server plugin |
required on the top of of each server plugin


name="foo"
specifies the name of the plugin


function apicall(uid,...)
see above


apievent(...)
calls the client plugin function
Bugs:

_______________________________________________________________________________________________________________________________________________________________________________
  1. no known bugs
TODO:
_______________________________________________________________________________________________________________________________________________________________________________
  • DOS protection on server
  • uid collision detection (currently a 1 in 18446744073709551616 chance so isnt much of a problem)
  • auto updater
  • more config options on server
  • more client functions
  • get contributors on github
Credits:

_______________________________________________________________________________________________________________________________________________________________________________


me - everything

Spoiler


if you are having trouble, try contacting me on #pixel before posting here
Edited on 07 August 2016 - 05:19 PM
Zudo #2
Posted 15 September 2013 - 02:29 AM
3 words:

This is AWESOME!!!!
amtra5 #3
Posted 15 September 2013 - 08:07 AM
Nice!
PixelToast #4
Posted 16 September 2013 - 12:52 AM
http://www.youtube.com/watch?v=8JbJiVnvN8g

program avalable at:
https://github.com/infinikiller64/HTTPNet/blob/master/Examples/chat

warning: you might have to restart the server, some http requests persist :s (am fixing that now)
nutcase84 #5
Posted 16 September 2013 - 08:31 AM
WOW. Sweet! I see myself using this for some things with my new secret project.
PixelToast #6
Posted 16 September 2013 - 03:05 PM
a bit of a large update, implemented timeouts and gave each connection its own ID so if it gets closed you dont have it receiving multiple times at once and i made it check if the server is valid
connections should be much much more reliable now :3
you can see the changes here:

https://github.com/i...3bd70fbc6e4b1ea

EDIT: colors :3

best thing ever coded in lua:

if config.rainbow then
local oprint=print
function print(str)
oprint(str:gsub(".",function(s) return "\27["..math.random(31,36).."m"..s end).."\27[0m")
end
end
note: colors dont work on windows
PixelToast #7
Posted 24 September 2013 - 03:12 PM
massive update!
https://github.com/P-T-/HTTPNet/commit/3f9932623033da7a04c4f374caea1b4b586218e9
API completely rewritten to support multiple instances
new identification system that makes sure there arent lingering connections
timeouts to prevents requests from persisting, default is 30s will probably add a config option for it
http events are now properly handled, you can now use http without getting leaked events
added new video showing the new API, see OP
amtra5 #8
Posted 24 September 2013 - 11:15 PM
http://www.computercraft.info/forums2/index.php?/topic/15226-potato/
I see what you did there ;)/>

Edit: Also, if I have time, I'm going to port your API to PHP, so static webpages can communicate to CC when they are loaded. (ie by Twillio)
PixelToast #9
Posted 24 September 2013 - 11:17 PM
http://www.computerc...c/15226-potato/
I see what you did there ;)/>
xD
yeah, you can put anything after 15226-

Also, if I have time, I'm going to port your API to PHP, so static webpages can communicate to CC when they are loaded. (ie by Twillio)
do you mean making the server in PHP (easiest solution is to rewrite the entire thing, sockets and all)
or do you mean a control panel thingy?

because making a control panel is really easy and it does not even require PHP, you can use javascript
Anavrins #10
Posted 25 September 2013 - 02:51 AM
This is really nice, I think I'm going to use this a lot :)/>
However do you have any plan of implementing the transmission of binary data?

Example: If I do "h:transmit(1337, 7331, string.char(250)), the receiver will receive "?", which then get decoded as 63 since "string.byte("?") = 63"
jay5476 #11
Posted 25 September 2013 - 06:09 AM
I believe that it should work only printing string.char(250) will give you "?" as this is the way cc prints unsupported characters but the byte should still be persistant
amtra5 #12
Posted 25 September 2013 - 08:22 AM
http://www.computerc...c/15226-potato/
I see what you did there ;)/>/>
xD
yeah, you can put anything after 15226-

Also, if I have time, I'm going to port your API to PHP, so static webpages can communicate to CC when they are loaded. (ie by Twillio)
do you mean making the server in PHP (easiest solution is to rewrite the entire thing, sockets and all)
or do you mean a control panel thingy?

because making a control panel is really easy and it does not even require PHP, you can use javascript
Control panel.

Also, JavaScript would definitely support many more languages, but I'm not really familiar with it XD
PixelToast #13
Posted 25 September 2013 - 12:22 PM
Also, JavaScript would definitely support many more languages, but I'm not really familiar with it XD
neither am I, still trying to properly make this ajax request c_c, all i have now is a form

EDIT:

This is really nice, I think I'm going to use this a lot :)/>
However do you have any plan of implementing the transmission of binary data?

Example: If I do "h:transmit(1337, 7331, string.char(250)), the receiver will receive "?", which then get decoded as 63 since "string.byte("?") = 63"
they dont actually turn into byte 63, that just means it cant display that character
there are some bytes that are eaten though, im fixing that by making the serializer allow escaping bytes

EDIT:

https://github.com/P-T-/HTTPNet/commit/db3f4d6167ccefdba06b77f3c61f8840f042045b
fixed :3
amtra5 #14
Posted 25 September 2013 - 08:24 PM
I'd like to ask what the eroutine function does. Is it specifically needed or just for CC?
Zudo #15
Posted 26 September 2013 - 12:15 PM
note: colors dont work on windows

Hehe, that helps me persuade people to use *nix systems :D/>
PixelToast #16
Posted 28 September 2013 - 09:41 PM
I'd like to ask what the eroutine function does. Is it specifically needed or just for CC?
its a lightweight multitasking API that does not use coroutines

This looks great! I might have to use it as an API later (if you don't mind of course)!
Also, o_o dat logo.
how did you make such an awesome logo?
i dont
i used gimp :3

After looking through the documentary of it, I think needs more user-friendliness.
Otherwise some people won't know how to use it even with your documentation.
(example: me, I'm going to have to read your source code to find out what I'm doing.)
the documentation is all you need, the code does lack comments, not sure what i should comment though

im currently working on a plugin system, there will be a example plugin that allows for password protected channels
Zudo #17
Posted 29 September 2013 - 07:48 AM
Thank god for apt-get.

SpoilerWow:
Hydrotronics #18
Posted 07 August 2016 - 01:41 PM
can I ask how to get this onto my CC computer?
JackMacWindows #19
Posted 07 August 2016 - 03:59 PM
Small tip: Macs can install LuaRocks with

brew install lua
where Homebrew is installed, apt-get is not present on Macs.
Anyways, looks cool! I would try it if LuaSocket would work on my Mac.
PixelToast #20
Posted 07 August 2016 - 07:15 PM
Holy necro batman, please close this thread mods
Lyqyd #21
Posted 07 August 2016 - 08:24 PM
Thread closed by request.