Jump to content




Push Notifications with HTTP API


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

#1 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 06 October 2015 - 09: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.

#2 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

Posted 06 October 2015 - 09: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!

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 October 2015 - 04: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.

#4 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 07 October 2015 - 01: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 by MKlegoman357, 07 October 2015 - 01:20 PM.


#5 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 07 October 2015 - 03:40 PM

Ok, I will take this information into consideration.

#6 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 07 October 2015 - 04: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 by Selim, 07 October 2015 - 04:48 PM.


#7 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 07 October 2015 - 05:24 PM

View PostSelim, on 07 October 2015 - 04:48 PM, said:

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?

#8 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 07 October 2015 - 06:02 PM

View Postwojbie, on 07 October 2015 - 05:24 PM, said:

View PostSelim, on 07 October 2015 - 04:48 PM, said:

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.

#9 Wojbie

  • Members
  • 631 posts
  • LocationKinda lost

Posted 07 October 2015 - 06:19 PM

View PostSelim, on 07 October 2015 - 06:02 PM, said:

I believe ComputerCraft connections time out after 30 seconds.
I meant on php side?

#10 Selim

  • Members
  • 189 posts
  • LocationHiding in Online Storage

Posted 07 October 2015 - 06:22 PM

View Postwojbie, on 07 October 2015 - 06:19 PM, said:

View PostSelim, on 07 October 2015 - 06:02 PM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users