Xojo.Net.HTTPSocket Multiple use

Hello guys,

I`m looking under the examples on developer.xojo.com on the particular example Using Slack and I want to do same thing but in my case to fetch the list of tables via an API, I build most of it and when I call 2 API calls one after another I get an Xojo.Core.UnsupportedOperationException saying [quote]A request is already in progress.[/quote], I did put [code]ClearRequestHeaders
Disconnect

[/code] on each end of the processing but some how the socked does not close and it cannot run the next query.

Any idea how I can achieve that ?

Due to the processing part I need those to run in some king of thread to update the interface, I`m just update some tables on a local database from remote so I need to show the upgrade progress, what would be the best option ?

Thank you .

You can’t make another request until the current request has finished processing. To avoid this I use xojo.core.timer.calllater to push the next request into the event loop which allows the current request to complete.

Any more specific details on this ? they are linked to the socket or do I have to make another piece of code to handle that ?

Thanks

I even tried putting the calls within timers and having them fire like every 2, 3 minutes from each other even if the call takes 3 seconds, I read that they have a. timeout of 1 min so even like that I get the same error. no idea why

Here’s a reusable class that works around this “feature”… Everything works the same as the original Xojo.Net.HTTPSocket except you can do multiple calls without getting that message/error

https://bitbucket.org/shaosean/xf/downloads/XFHTTPSocket_1.0.0.zip

This code is in the public domain, so feel free to use it without worries…
http://unlicense.org

Thanks again

You’re welcome.

One little question,

If I understood right, the PageReceived is calling that mPageReceived and queue the calls with that timer, now, same like in the slack sample I put all my calls in the PageReceived EventHandler, in this case where should I put all those ? Would they be better in the Page Received after the Timer part or in the mPageReceived ?

I do have few event handlers that are processing the data and push it to the event definitions to be fetched and processed .

Thanks again .

I did tried to replace the current Connector class with a super of your class and in the PageReceived handler I have the code

[code]If HTTPStatus <> 200 Then
APIError(HTTPStatus, Content)
Return
End If

Dim ResponseText As Text

ResponseText = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(Content)

Dim json() As Auto
json = Xojo.Data.ParseJSON(ResponseText)

Dim method As String = GetAPIMethod(URL)

Select Case method

Case “Users”
ProcessUsersList(json)
Case “Tenants”
ProcessTenantsList(json)
Case "Units "

End Select

[/code]
that calls the methods within class and process the data then pushes it to the event definitions of the same class.

Even if I do this I get the same result, it fetches the first query and the second query it stops .

So I I have the following calls, Users , Tenants, Units, once it reaches to Tenants I get same error.

Thanks again.

Don’t write any code in the XFHTTPSocket class… Either create an instance in code, or by dragging a copy to a window… The PageReceived event will happen in that instance (the PageReceived event is first called in the sub-class, which forwards it to mPageReceived which then calls the new PageReceived event that your instance will do what it needs to do…

Your code above doesn’t really help me, if you want, message me through here or email me and I’d be glad to look at your code and see what we can do…

Smarter people than me found that Xojo.Core.Timer.CallLater feature and I’ve used it in a couple of projects for work…

[quote=358185:@shao sean]Don’t write any code in the XFHTTPSocket class… Either create an instance in code, or by dragging a copy to a window… The PageReceived event will happen in that instance (the PageReceived event is first called in the sub-class, which forwards it to mPageReceived which then calls the new PageReceived event that your instance will do what it needs to do…

Your code above doesn’t really help me, if you want, message me through here or email me and I’d be glad to look at your code and see what we can do…

Smarter people than me found that Xojo.Core.Timer.CallLater feature and I’ve used it in a couple of projects for work…[/quote]

Hello Sean,

IT seems that I`m getting same thing even if I use that so I definitely do something wrong,

Unfortunately I cannot share the app as it has an internal api and the data that I strictly signed for it but it will be nice to have an example where I can fetch let’s say 8 requests one after another for me to process, any api that has a data for testing.

so I did the api to export 8 tables, the content, so once I fetch those I have to populate them on a local database , so this thing will be 2 way and the way I want to doit is trough a thread so I can update as well the user interface on progress.

I will try to do more tests and let you know how it goes .

Thanks again.

https://bitbucket.org/shaosean/xf/downloads/XFHTTPSocket_test.zip

Click the button and the listbox will get populated with the domain names of the sites the HTTPSocket is calling, one after another, in the PageReceived event… When the entry “-- fin --” is entered, it is done…

The above links aren’t working, so here are new links… Sorry about that…

http://securedhosting.tk/files/xojo/XFHTTPSocket_1.0.0.zip
http://securedhosting.tk/files/xojo/XFHTTPSocket_test.zip

[quote=369983:@shao sean]The above links aren’t working, so here are new links… Sorry about that…

http://securedhosting.tk/files/xojo/XFHTTPSocket_1.0.0.zip
http://securedhosting.tk/files/xojo/XFHTTPSocket_test.zip[/quote]

These links don’t seem to work either. Do you have a new link?