"Hacking" Xojo.Net.HTTPSocket

Hi guys,

I’m working on the next version of Roo, my drop-in replacement for Xojoscript and I’m adding basic support for networking. Specifically I want to add support for HTTP GET and POST requests as the other app I’m working on which uses Roo as its scripting language needs that support.

Ultimately I want to be able to do this with Roo:

var request = Request();
request.headers = {"Accept" => "text/plain", "Connection" => "keep-alive"};
request.method = HTTP.GET;
request.url = "https://example.com";
var response = request.send; # Make the request.
print(response.content); # Prints the content of the response.

I will be backing Roo’s networking class with the Xojo.Net.HTTPSocket class. I know that this did away with synchronous requests but I’m hoping someone can help me figure out a way to hack together a synchronous call with it. Perhaps with a Timer? I know asynchronous requests are best but like I said, Roo is an imperative language (NOT event driven) and therefore I don’t want the code after the network call to execute until the network request is finished.

Does anyone have any ideas? I don’t want to use the legacy HTTPSocket class as I want to provide HTTP 1.1 support.

If you start the request from inside a thread, you can suspend the thread after you call Xojo.Net.HTTPSocket.Send, then in the PageReceived event, resume the thread. From the main thread though, it’s impossible without abusing DoEvents like the classic HTTPSocket does. I would very strongly advise against that.

Thanks Thom - that’s a novel approach. I think I might try that. It should be possible without too much refactoring of the interpreter.

Out of interest, why does everyone hate the dreaded App.DoEvents?

Because in a desktop app, the framework is already running the event loop for you. You really do not want to run another event loop inside that one.