« Vote for FileMaker Pl… | Home | Xojo 2018 Release 1 »

Xojo.Net.HTTPSocket and Timeouts


For writing a web service client with Xojo you can go three ways for your socket stuff. First you can use HTTPSocket class, which still is in a lot of old projects. Or you go with newer Xojo.Net.HTTPSocket class, which sadly misses some features like timeouts. Or you go via plugin and use for example CURL class.

Last year I moved a client app from old HTTPSocket to Xojo.Net.HTTPSocket to get HTTP 1.1 support and proxy handling. Oh, well, I should have gone the plugin way as now client asks for a timeout. Some requests take longer than 2 minutes on server to provide responds and we get timeout errors in the app.

Before we switch everything to CURL, I checked for an easier way and looked into patching the Xojo class to use new timeout. Looking on a stack trace on how it works, you see this:
4 Window1.Window1.Event_Open%%o  (in test.debug) + 574
4 Xojo.Net.HTTPSocket.Send%%oyy (in test.debug) + 63
4 HTTPSocket_Send (in XojoFramework) + 83
4 HTTPSocketImpNS::Send(Text const&, Text const&) (in XojoFramework) + 312
4 HTTPSocketImpNS::StartConnection(Text const&, Text const&) (in XojoFramework) + 478
4 -[NSURLConnection initWithRequest:delegate:startImmediately:] (in CFNetwork) + 43
4 -[NSURLConnection(Private) _initWithRequest:delegate:usesCache:maxContentLength:startImmediately:connectionProperties:] (in CFNetwork) + 190
4 -[NSURLConnectionInternalConnection initWithInfo:] (in CFNetwork) + 1301
As you see the Xojo.Net.HTTPSocket class is implemented in C++ code and uses NSURLConnection class on Mac for the job. So I created a new NSURLConnectionFilterMBS class, which allows you to filter the call to initWithRequest:delegate:startImmediately: function. All calls to initWithRequest:delegate:startImmediately: are intercepted, our event FilterConnection event is triggered and you can modify the request, before the connection is created. So for Mac at least we can fix the timeout issue.

Coming soon in next prerelease for MBS Xojo Plugins 18.2.
17 04 18 - 16:20
No comments

  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.