My server's response will have a Content-Type: text-eventstream and will remain open.
Can GameMaker connect to such an endpoint and receive async events? If so, could someone please show how this is done?
If not, how can a server (C#) send events to a GameMaker game (which must work as native mobile and also HTML 5).
Thanks!
Your server should be or include a websocket server. Once your game(client) connects to it, your server can use that open connection to continuously send data.
I'm also interested in any different solutions.
Thanks Russell
That seems to be an async request to retrieve data via HTTP GET, but only a complete request (i.e. all data until the socket closes).
What I need is for the socket to remain open, and for GM to give me each chunk of data as it is received rather than all of it at the end. For example, if you visit this URL you will see the browser constantly shows it is loading the page, and messages come in every 5 seconds. The request never completes, but data is received constantly.
http://mrpmorris-event-stream.azurewebsites.net/events
as packets are received you will get event callbacks so you will get the partials how you handle that is up to you.
Russell
as packets are received you will get event callbacks so you will get the partials how you handle that is up to you.
Russell
Hi
@rwkay
! - finally got access to this forum in work...
Just checking / adding more background / info, as
@MrPMorris
has been looking into helping me out...
...SO, if I fire off just ONE HTTP get/post, are you saying that the response ID I get (and subsequently act upon/check for, in the HTTP ASYNC event) remains the SAME for the subsequent data pushed in response to the initial HTTP request, and will fire off the async event each time new data is 'pushed' back to GM through that channel?
....OR, did you mean that as that initial get/post request keeps responding with more data from the connection that was initiated, the HTTP ASYNC event will keep firing off, but maybe doesn't retain or re-set the original response ID, and I just need to act on ANYTHING I get back, as I get it back, instead simply adding the extra step of interrogating say, an info field within the data that I receive, to figure out what it is and what to do with it?
Many thanks again Russell!!
If the stream never ends, I would assume the buffer used for storing normal non streaming requests to eventually cause out of memory errors.
Hey mate!
Thanks as always for the input! - it's more that it wouldn't end, but JUST stays open for the life of a single game - maybe 5-10 minutes, maybe longer, but not rapid-fire data, more game status on the server etc?
Should be okay then? - and could we reset or clear the buffer at points if it was going to be an issue? - I think the important thing is that we were hoping for it to not be a polling system, but a push (and only on push, unless the active client is to send an action) system?
Cheers again man...
Hey mate!
Thanks as always for the input! - it's more that it wouldn't end, but JUST stays open for the life of a single game - maybe 5-10 minutes, maybe longer, but not rapid-fire data, more game status on the server etc?
Should be okay then? - and could we reset or clear the buffer at points if it was going to be an issue? - I think the important thing is that we were hoping for it to not be a polling system, but a push (and only on push, unless the active client is to send an action) system?
Cheers again man...
With a regular http_get() style call, it does not look like you have access to the data received so far, and it is only after all data has been received you get the data. If the stream does not end, you have no data.
Create event
req = http_get("https://www.cnn.com/");
Async - HTTP
if (async_load[? "id"] == req) {
show_debug_message(string(async_load[? "sizeDownloaded"]) + ", " + string(async_load[? "contentLength"]) + ", " + string(ds_map_keys_to_array(async_load)));
if (async_load[? "status"] == 0) {
show_debug_message("Finished downloading " + string(string_length(async_load[? "result"])) + " characters");
983040, 1113973, [ "contentLength","url","id","status","sizeDownloaded" ]
1015808, 1113973, [ "contentLength","url","id","status","sizeDownloaded" ]
1048576, 1113973, [ "contentLength","url","id","status","sizeDownloaded" ]
1081344, 1113973, [ "contentLength","url","id","status","sizeDownloaded" ]
undefined, undefined, [ "response_headers","http_status","url","id","status","result" ]
Finished downloading 1113692 characters
So
result
, which contains the desired data is only available in
async_load
upon successfully receiving the complete response. You also have no way to stop a transfer request from the client side. It will either succeed or fail, you cannot interrupt it (as far as I know). You can't do anything with the buffer.
You obviously have more control over things if you used networking functions and async callback instead of HTTP requests.
With a regular http_get() style call, it does not look like you have access to the data received so far, and it is only after all data has been received you get the data. If the stream does not end, you have no data.
That is what I both suspected and feared. Thanks very much for taking the time to prove your answer, I appreciate it very much!
@rwkay
I don't suppose you have code that proves the opposite, do you?