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

Zombienet - Http, Cross Server Communication!

Started by Sxw, 04 October 2013 - 04:54 PM
Sxw #1
Posted 04 October 2013 - 06:54 PM
Zombienet is a framework to let you communicate over http, cross server.

Usage:
Spoiler1. Download (pastebin get xqdNSNwY zn) and os.loadAPI("zn")

2. Call zn.start([channel])
Channel is optional, and if omitted, will generate a random one
Returns: true, channel, sid (for advanced uses)

3. zn.poll()
Returns:
No message: false, "nomsg"
Message: true, "message here"

4. zn.send(msg)
Sends a message to the channel

5. zn.daemon (Run in coroutine)
Runs in background and queues zn_msg(msg) whenever there is a new message.

Notes:
SpoilerThis runs on my server, so please don't abuse it. If there is enough interest, I might publish instructions for running your own.
For science!

Download:
pastebin.com/xqdNSNwY
pastebin get xqdNSNwY zn
Edited on 15 December 2013 - 03:26 PM
PixelToast #2
Posted 04 October 2013 - 07:07 PM
i have to say this, but Zombienet was actually developed before httpnet
so no flamewars about stealing .-.
MudkipTheEpic #3
Posted 04 October 2013 - 07:33 PM
Telling programmers "don't mess with my server" is equivalent to telling a thief "don't touch my stuff".
Yevano #4
Posted 04 October 2013 - 07:58 PM
Telling programmers "don't mess with my server" is equivalent to telling a thief "don't touch my stuff".

Yes, you can always use the "For science!" excuse.
Zudo #5
Posted 05 October 2013 - 12:18 AM
I like the idea of queuing an event when a message is received.
alakazard12 #6
Posted 20 October 2013 - 08:38 AM
I tried doing something like this 6 months ago, but I couldn't get it to work with 000webhost because it was sending too many messages to the site, and 000webhost blocks that .-.
PixelToast #7
Posted 20 October 2013 - 04:02 PM
I tried doing something like this 6 months ago, but I couldn't get it to work with 000webhost because it was sending too many messages to the site, and 000webhost blocks that .-.
its verry hard to do in php
well properly that is, the proper way is to only serve the request only when its needed (long polling)
the way php was designed makes this hard to do without being slow, taking up unnecicary threads, etc
this can be done in node.js pretty easialy though, but i prefer luvit because it is lua
though i would like plugins have access to libraries like sqlite, thats why i use normal lua
skwerlman #8
Posted 02 December 2013 - 07:09 PM
This looks great! I'd definitely like to have it running on my server! Any chance you could post those instructions?
Sxw #9
Posted 14 December 2013 - 12:18 PM
Well, the current code is kinda messy, but you could make your own server. The protocol is very simple. But the main point of this is cross server communication, so it might be better to just use my server. For reference:
Spoilerzn.fluidnode.com/obtain
Grab session id for channel or random channel.
zn.fluidnode.com/send
Sends a message to session id's channel.
zn.fluidnode.com/poll
Returns a message from session id's message queue
gknova61 #10
Posted 14 December 2013 - 07:30 PM
Could we get a tutorial and/or the scripts you're using server-side? The website directory? I just want to see how the current code works messy or not and host it on my server so it's more reliable for me.

Edit: When I try to use the API to just get a key, it errors with cannot connect to the server, too.
Edited on 14 December 2013 - 06:37 PM
ardera #11
Posted 15 December 2013 - 08:01 AM
it's because he's missing an / in the serv variable.

It tries to connect to "http://zn.fluidnode.comobtain" instead of "http://zn.fluidnode.com/obtain".


EDIT:
zn.fluidnode.com/send
Sends a message to session id's channel.
Does that mean I'm sending messages to a session ID, instead of sending them to a channel?
I thought it works like rednet, multiple computers can join a channel and they only receive messages from this channel.

What is a session ID then?
Edited on 15 December 2013 - 08:48 AM
Sxw #12
Posted 15 December 2013 - 04:24 PM
I fixed the code on pastebin. Not missing a / anymore. Lemme post the code.
Server in node.js(uses private base library): http://pastebin.com/9sV3ws4i
A session id is basicly an inbox.
Also updated tutorial to be more clear.
Edited on 15 December 2013 - 03:26 PM
ardera #13
Posted 16 December 2013 - 08:51 AM
Polling / Sending still doesn't work, "Unable to connect to server". Also, calling the poll/send URL's in browser works.

It seems like CC interprets 4xx status codes as a http_failure, you should set the status codes to 200 instead of 4xx in your Server, then I'm sure it'll work.
Sxw #14
Posted 17 December 2013 - 05:25 PM
I hate http. xD. Should be fixed soon.
ardera #15
Posted 18 December 2013 - 02:48 PM
still doesn't work for me, "query invalid" :P/>

Got it working using this function instead of http.post in "aObtain" (not needed there), "aPoll" and "aSend":
Spoiler

local function fetch(url, params)
if params then
  params = "?"..params
else
  params = ""
end
url = url..params

http.request(url)
while true do
  local ev, p1, p2 = os.pullEvent()
  if ev == "http_success" then
   return p2
  elseif ev == "http_failure" then
   return
  end
end
end
Edited on 18 December 2013 - 01:49 PM
Sxw #16
Posted 19 December 2013 - 10:42 PM
This was a server-side issue where it wasn't parsing POST correctly. I didn't use GET for security reasons. I want to get an HTTPS cert for my domain but for now, oh well. All fixed now. No modified client is needed.
ardera #17
Posted 21 December 2013 - 06:02 AM
Thanks, I think it works now :)/>