196 posts
Location
Hiding in Online Storage
Posted 06 October 2015 - 10:01 PM
So, from my understanding of how push notifications work on other platforms is that the connection with the server is never closed, and that allows for much faster and easier notification handling so that a device does not have to check for data at an interval.
From what I understand of the ComputerCraft HTTP API it is not possible to keep a connection open for purposes like this, correct?
All I am asking is if it is realistically possible to have push style notifications in ComputerCraft.
212 posts
Location
Somewhere in this dimension... I think.
Posted 06 October 2015 - 10:09 PM
I don't think so no, but you can try HTTP headers such as a keep-alive. I am not sure how LuaJ and Java handle it so experiment!
7083 posts
Location
Tasmania (AU)
Posted 07 October 2015 - 05:38 AM
Indeed, you can't handle things in that manner. ComputerCraft scripts must request data when they want it. If they want notifications "as they happen", then they have to keep asking for them.
1140 posts
Location
Kaunas, Lithuania
Posted 07 October 2015 - 02:12 PM
I know somebody actually used a pretty clever solution for this. When you send a request to a server the server will not respond until a notification arrives (or the connection timeouts, which was 30 seconds). So if you are able to make the server hold the request for some time without sending a response you could do those instant notifications.
EDIT: here's the original idea:
Mote.
Edited on 07 October 2015 - 12:20 PM
196 posts
Location
Hiding in Online Storage
Posted 07 October 2015 - 04:40 PM
Ok, I will take this information into consideration.
196 posts
Location
Hiding in Online Storage
Posted 07 October 2015 - 05:48 PM
Ok, I found my solution. All I am doing for those who are interested, I am just calling sleep(1) on the server end in PHP until it finds a file with the notification data in it.
Edited on 07 October 2015 - 03:48 PM
724 posts
Location
Kinda lost
Posted 07 October 2015 - 06:24 PM
Ok, I found my solution. All I am doing for those who are interested, I am just calling sleep(1) on the server end in PHP until it finds a file with the notification data in it.
So if there is no file it will never return and loop forever? Or did you include some kind of sanity test in there?
196 posts
Location
Hiding in Online Storage
Posted 07 October 2015 - 07:02 PM
Ok, I found my solution. All I am doing for those who are interested, I am just calling sleep(1) on the server end in PHP until it finds a file with the notification data in it.
So if there is no file it will never return and loop forever? Or did you include some kind of sanity test in there?
I believe ComputerCraft connections time out after 30 seconds.
724 posts
Location
Kinda lost
Posted 07 October 2015 - 07:19 PM
I believe ComputerCraft connections time out after 30 seconds.
I meant on php side?
196 posts
Location
Hiding in Online Storage
Posted 07 October 2015 - 07:22 PM
I believe ComputerCraft connections time out after 30 seconds.
I meant on php side?
I will be adding a counter for it to only check so many times first, then have close the connection. If the computer ends the connection first, the PHP script should stop.