Xojo.Net.HTTPSocket Multiple use

  1. last week

    Aurelian N

    Nov 8 Pre-Release Testers, Xojo Pro
    Edited last week

    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

    A request is already in progress.

    , I did put ClearRequestHeaders Disconnect 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 .

  2. Wayne G

    Nov 8 Pre-Release Testers, Xojo Pro New Zealand axisdirect.nz

    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.

  3. Aurelian N

    Nov 8 Pre-Release Testers, Xojo Pro

    @Wayne G xojo.core.timer.calllater

    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

  4. Aurelian N

    Nov 8 Pre-Release Testers, Xojo Pro

    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

  5. shao s

    is not verified Nov 8 Sudbury, Ontario, Canada
    Edited last week

    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

  6. Aurelian N

    Nov 8 Pre-Release Testers, Xojo Pro

    Thanks again

  7. shao s

    is not verified Nov 8 Sudbury, Ontario, Canada

    You're welcome.

  8. Aurelian N

    Nov 8 Pre-Release Testers, Xojo Pro

    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 .

  9. Aurelian N

    Nov 8 Pre-Release Testers, Xojo Pro

    I did tried to replace the current Connector class with a super of your class and in the PageReceived handler I have the 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
    

    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.

  10. shao s

    is not verified Nov 8 Sudbury, Ontario, Canada

    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..

  11. 3 days ago

    Aurelian N

    Nov 13 Pre-Release Testers, Xojo Pro

    @shao s 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..

    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.

  12. shao s

    is not verified Nov 13 Sudbury, Ontario, Canada

    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..

or Sign Up to reply!