The thing is, even when I comment out my "sync" code that makes the game 
wait, it still doesn't work. Without pausing the main loop and without 
sleep calls, my net_httpGet function returns false immediately, but the 
game still runs, and callback happens a bit later, but it's always status 0 
and message is NULL, so I don't know what's wrong. Under what conditions 
does this happen? 

Ok, I searched through Emscripten source, and by modifying it a bit, I 
located where the call happens:
emscripten_async_wget2_data: function(url, request, param, arg, free, 
onload, onerror, onprogress) {
  var _url = Pointer_stringify(url);
  var _request = Pointer_stringify(request);
  var _param = Pointer_stringify(param);

  var http = new XMLHttpRequest();
  http.open(_request, _url, true);
  http.responseType = 'arraybuffer';

  var handle = Browser.getNextWgetRequestHandle();

  // LOAD
  http.onload = function http_onload(e) {
    if (http.status == 200 || _url.substr(0,4).toLowerCase() != "http") {
      var byteArray = new Uint8Array(http.response);
      var buffer = _malloc(byteArray.length);
      HEAPU8.set(byteArray, buffer);
      if (onload) Runtime.dynCall('viiii', onload, [handle, arg, buffer, 
byteArray.length]);
      if (free) _free(buffer);
    } else {
      if (onerror) Runtime.dynCall('viiii', onerror, [handle, arg, 
http.status, http.statusText]);
    }
    delete Browser.wgetRequests[handle];
  };

  // ERROR
  http.onerror = function http_onerror(e) {
    if (onerror) {
      Runtime.dynCall('viiii', onerror, [handle, arg, http.status, 
http.statusText]);  <--- HERE!
    }
    delete Browser.wgetRequests[handle];
  };

  // PROGRESS
  http.onprogress = function http_onprogress(e) {
    if (onprogress) Runtime.dynCall('viiii', onprogress, [handle, arg, 
e.loaded, e.lengthComputable || e.lengthComputable === undefined ? e.total 
: 0]);
  };

  // ABORT
  http.onabort = function http_onabort(e) {
    delete Browser.wgetRequests[handle];
  };

  // Useful because the browser can limit the number of redirection
  try {
    if (http.channel instanceof Ci.nsIHttpChannel)
    http.channel.redirectionLimit = 0;
  } catch (ex) { /* whatever */ }

  if (_request == "POST") {
    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", 
"application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", _param.length);
    http.setRequestHeader("Connection", "close");
    http.send(_param);
  } else {
    http.send(null);
  }

  Browser.wgetRequests[handle] = http;

  return handle;
},

So, it's being called as XMLHttpRequest onerror handler, but it gives me 
zero as status and no message. At least I know now that it isn't in the 
onload() call if HTTP status is different than 200 or the URL doesn't start 
with http. But still - why? What makes this XMLHttp request fail in such a 
way?

On Friday, November 14, 2014 9:08:30 PM UTC+1, Sergey Kurdakov wrote:
>
> Hi Alexandar,
>
> as it was me, who advised - emscripent_wget - if you try to search code is 
> done around async xmlhttprequest , it works just fine if it is used in 
> async way.
>
> if you want how to make things, there is an engine 
> https://github.com/floooh/oryol which implements IQ queues such that 
> after you got response it is stored and on next tick you can get if from IO 
> queue  
>
> it is possible to make things sync, but that requires deeper knowledge of 
> internals so most probably you will fail with that.
>
> thus my suggestion - to keep things async as if you used pure 
> xmlhttprequest
>
> Regards
> Sergey
>
>
>
> On Fri, Nov 14, 2014 at 10:43 PM, Aleksandar Stančić <[email protected] 
> <javascript:>> wrote:
>
>> I tried wget2_data now and it still doesn't work. It seems it isn't even 
>> trying to download the file, it's not HTTP related, as with v2 I 
>> immediately get onerror callback and error code is 0, and my error message 
>> is NULL, so I still have no clue what is going on. I am relatively new to 
>> Emscripten, so I might be missing something. Do I need some special 
>> settings for compiler and/or linker to make this work? Anything 
>> browser-related? I tested on latest Firefox and Chrome on Linux, same thing 
>> every time.
>>
>> On Thursday, November 13, 2014 11:36:36 AM UTC+1, Sergey Kurdakov wrote:
>>>
>>> Hi Alexandar,
>>>
>>> >won't emscripten_async_wget serve your needs? 
>>>
>>> I mean set of functions
>>>
>>> emscripten_async_wget
>>> emscripten_async_wget2
>>> emscripten_async_wget_data
>>> emscripten_async_wget2_data
>>>
>>> Regards
>>> Sergey
>>>
>>>
>>> On Thu, Nov 13, 2014 at 1:24 PM, Sergey Kurdakov <[email protected]> 
>>> wrote:
>>>
>>>> Hi Alexandar.
>>>>
>>>> won't emscripten_async_wget serve your needs? it sends requests to 
>>>> server and params can adjast which type of request is sent.
>>>>
>>>> Regards
>>>> Sergey
>>>>
>>>> On Thu, Nov 13, 2014 at 11:58 AM, Aleksandar Stančić <[email protected]
>>>> > wrote:
>>>>
>>>>> Hi! I'm writing a game in C++/OGL (to be published on the web through 
>>>>> Emscripten) that needs some interaction with a server, written in 
>>>>> PHP/MySQL. I already prepared the database and PHP code, and now, the 
>>>>> surprisingly difficult part is connecting the two. Is there a simple way 
>>>>> of 
>>>>> loading a web page with a few POST strings in C++/Emscripten? 
>>>>> Two-to-three 
>>>>> strings go in (POST) and I need to read one string or integer on the 
>>>>> output 
>>>>> (HTTP response). emscripten_wget just hangs on me, and mixing JS + C++ 
>>>>> seems to be able to transfer only numbers (ASM). Can someone point me in 
>>>>> the right direction? I feel like I'm missing something obvious, and I 
>>>>> wouldn't really know, since I'm not much of a web developer. Thanks.
>>>>>
>>>>> Just to clarify, I have a PHP page like this:
>>>>>
>>>>> $a = $_POST['a']  // a and b need to come from C++
>>>>> $b = $_POST['b']
>>>>>
>>>>>
>>>>>
>>>>> // do stuff with $a & $b
>>>>>
>>>>>
>>>>> echo($c)  // a string, under 100 regular ASCII chars, nothing special
>>>>>
>>>>> So, I need to do a HTTP POST request (I can switch to GET if that'll 
>>>>> make things easier), and read a single line of text back into C++.  What 
>>>>> would be a good way of doing that? I hate to be *that guy**,* but it 
>>>>> is kind urgent (I really wrote myself into a corner with this one, I 
>>>>> expected this to be easy), so any tips are greatly appreciated.
>>>>>
>>>>>  -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "emscripten-discuss" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to [email protected].
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to