Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / HTTP custom header read?

Author
Message
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 23rd Apr 2015 15:17 Edited at: 23rd Apr 2015 15:17
Hello I want to write custom headers to read in AppGameKit, is this possible?

This in PHP "header('Location: test.html', true)" returns the content of test.html.

This in PHP "header(': custom content', true)" returns nothing.

Is it possible to get custom data in AppGameKit from a PHP script?

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Apr 2015 15:25 Edited at: 24th Apr 2015 10:39
You can send anything you like back from PHP. I have used it to return text files with high scores.

For example, this returns a set of high scores with no headers or other data...



Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 23rd Apr 2015 15:31
How do you send that data to an AppGameKit app?

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 23rd Apr 2015 16:42
You need to poll the php page for a request.
Or you need to open a server socket to listen to.

Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 23rd Apr 2015 16:57
I set up a HTTP connection and requests a page containing a header, this header can return the content of a HTML page which it directs to, but I can't read a custom header.

Can I use sockets in the BASIC tier?

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 23rd Apr 2015 17:07 Edited at: 23rd Apr 2015 17:10
No you need tier 2...
But in tier 1, do a php with a set of commands...

If(command == 'givemeinfo'){
Text = "yourinfo";
}
Send header as plain text so you can get the response as text or json format or arrays or objects.

Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 23rd Apr 2015 17:13 Edited at: 23rd Apr 2015 17:23
How do I send plain text? I tried header('text') but that returns nothing.

EDIT: I tried setting Content type to plain text but I still don't receieve any text.

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Apr 2015 17:25 Edited at: 23rd Apr 2015 17:28
Run this AppGameKit code that points to my server. It will run the PHP code above and return a simple string of data.

The string is meaningless outside of the context of my game, but you can see that you can return anything at all.



If you want to see what it returns in a browser, click here. View the source and you will see there are no headers, it is simply text.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 23rd Apr 2015 17:28
Yes, I do get a reply. Is the data dynamically created? I can get static text from a HTML file but not anything I create dynamically.

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 23rd Apr 2015 22:20
You must code a PHP server side for Dynamic Text.
So a more complex php page or process on linux.

BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Apr 2015 10:39 Edited at: 24th Apr 2015 11:01
It is this code that creates the reply:



It's a simple database query that then uses echo to send the result. This is also just as valid as a PHP page:



Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 24th Apr 2015 12:46
Thanks a lot! I didn't realise that echo could be the response It is all good now

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 24th Apr 2015 13:13
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 27th Apr 2015 14:10
I have another problem now. I keep getting a response from GetHTTPResponse(). How do I empty that response? I don't think my PHP script is running multiple times, only once.

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Apr 2015 14:28
GetHTTPResponse() is populated once, and then can be queried forever. So you use GetHTTPResponseReady() and soon as it reads 1, you read the response once and then continue with the rest of your program.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 27th Apr 2015 14:32 Edited at: 27th Apr 2015 18:08
But GetHTTPResponseReady() also keeps returning 1.

if GetHTTPResponseReady(http) = 1
response$ = GetHTTPResponse(http)
endif

EDIT: I use SendHTTPRequestASync() by the way.

EDIT 2: I solved it by deleting connection after each reply, which is not good as I want several replies for each user.

EDIT 3: Can I have multiple HTTP connections open?

EDIT 4: I think I know how to do this now an array with user id's from network connections, each user ID have their own HTTP connection which wait for response, then close the connection, send user onwards in the system and remove them from the array.

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Apr 2015 18:43
It sounds like you've got it!

HTTPResponses are a "throw away" resource. Every time you go to a web page in a browser you are creating a new response. It sometimes feels like a waste of resources, or more intensive than it should be...but in this case it is OK as long as you keep deleting the responses once you've processed them (or reuse them).

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Login to post a reply

Server time is: 2024-03-28 21:18:41
Your offset time is: 2024-03-28 21:18:41