• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Snippet PubNub - REST Api usage

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,597
Hi folks,

if you consider using http://www.pubnub.com for your network needs, here is a small script to show how to use http requests for it:

Cerberus:
Strict

' PubNub.Com example of their REST API

Import mojo
Import brl.httprequest

'-----------------------------------------------------------------
Class myClass Extends App Implements IOnHttpRequestComplete

    Field get_req:HttpRequest

    '-----------------------------------------------------------------
    Method OnHttpRequestComplete:Void( req:HttpRequest )

        If req=get_req
            Print "Http GET complete!"
        Endif

        Print "Status="+req.Status()
        Print "ResponseText="+req.ResponseText()
   
    End
    '-----------------------------------------------------------------
    Method OnCreate:Int()
        SetUpdateRate 60
   
   
        'Buildung up the Pubnub string

        'Publish
        Local pubKey:String = "demo"
        Local subKey:String = "demo"
        Local signature:String = "0"
        Local channel:String = "hello_world"
        Local callback:String = "0"
        Local message:String = "%22Hello%20World777%22"
   
        Local pubnubP:String = "publish/"   + pubKey + "/" + subKey  + "/" + signature + "/" + channel + "/" + callback + "/" + message
   
        'History
        Local limit:String = "3"
        Local pubnubH:String = "history/"   + subKey + "/" + channel + "/" + callback  + "/" + limit
   
        'Subscribe
        Local timeToken:String = "0"
        Local pubnubS:String = "subscribe/" + subKey + "/" + channel + "/" + callback  + "/" + timeToken

        get_req=New HttpRequest( "GET","http://pubsub.pubnub.com/"+pubnubH,Self )
        get_req.Send

        Return 0
    End
    '-----------------------------------------------------------------
    Method OnUpdate:Int()
        If KeyHit( KEY_CLOSE ) Error ""

        UpdateAsyncEvents()
        Return 0
    End
    '-----------------------------------------------------------------
    Method OnRender:Int()
        ' here you render your app
        Cls 0,0,128
        SetColor 128,128,128
        DrawText "Http GET bytes received="+get_req.BytesReceived(),0,0
        Return 0
    End
End

'-----------------------------------------------------------------
Function Main:Int()
    New myClass
    Return 0
End
 

Attachments

  • 1548881508938.png
    1548881508938.png
    64.8 KB · Views: 248
Last edited:
Look good and working. When I test with my website the responsetext is null. Could you help me understand this thing...

I use monkey 79e currently and plan to port to lates CerberusX. In my code, I send and receive data using http request. It's all working before. The link is: ~EDIT~

That for my game high score. I process the string that I receive to make a table.
 
Last edited:
To make this clear. It worked at some time.... and now does not work anymore? Your own code and website?

This code above is for Pubnub. It would never work on your site.
 
> It worked at some time.... and now does not work anymore?

I't still work on MX 79e. But not work on CX. What I mean is, If I use the above code and replace with my http address above, its work in MX but in CX the response text return Null. In MX I get the responsetext. (The responsetext is exactly the same when I open in browser).

> Your own code and website?

Yes. It is a simple php with sql to record my user highscore. From my game I use httprequest to send data to update highscore. the php send back current highscore in just a text. I then process the string to make a proper gui. Its a stupid temporary solution actually...because at that time I cannot integrated googlegameservice and I need a highscore system.

Sorry if this is so stupid. ;)
But on old MX I can read responsetext() from that http address. I don't know, not an expert on this area. Is there any thing I should do on server to allow client reading httprequest? Suppose, we should be a able to get httprequest from any address right?
 
To my knowledge, on the HTML target we didn't change anything.
MX 79e is super old, MX was on 87f the last I think.
I have to investigate. As you don't provide any code and stuff I can try, I will need time to build something.
 
| As you don't provide any code and stuff I can try, I will need time to build something

You can use the above code and replace with my http address.
 
So it is a bug.. https://www.cerberus-x.com/community/threads/http-get-onhttprequestcomplete.395/

Btw... I delete my http link that I provide earlier. No use anymore. Thank you @Mike for taking time to examine it
I am not sure about it anymore. I have installed Monkey 79d and it does not return anything with your webadress on HTMl5 but with PubNub it does with my code
Regarding the bug I suspected.... It could be a time out which we introduced and should be set higher in CX.
But with Monkey it doesn't have that...


So please provide code that runs in Monkey 79d but not in CX.
 
This sample code for reconstruct the error:
Compile android MX 79e = Run OK
Compile android CX 20180302 = App terminate
i'm not sure why.. could it be my site?

Code:
Strict
Import mojo
Import brl.httprequest
Class myClass Extends App Implements IOnHttpRequestComplete
    Field get_req:HttpRequest
     Field ResponseText:String
    Method OnHttpRequestComplete:Void( req:HttpRequest )
        If req=get_req
              ResponseText =req.ResponseText()
        Endif
    End
    Method OnCreate:Int()
        SetUpdateRate 60
        get_req=New HttpRequest( "GET","http://nvgamepad.com/temp/highscore.php",Self )
        get_req.Send
        Return 0
    End
    Method OnUpdate:Int()
        If KeyHit( KEY_CLOSE ) Error ""
        UpdateAsyncEvents()
        Return 0
    End
    Method OnRender:Int()
        PushMatrix()
              Scale (3,3)
              Cls 0,0,0
              SetColor 255,255,255
              DrawText "Http Request:",0,0   
              If ResponseText=""
                    DrawText "Waiting..",0,50   
              Else
                    DrawText "Response Text received:",0,25   
                    DrawText ResponseText,0,50   
              Endif
        PopMatrix()
        Return 0
    End
End
Function Main:Int()
    New myClass
    Return 0
End
 
Back
Top Bottom