Android Question Simplest mechanism for communicating with central server

Discussion in 'Android Questions' started by Scott Bartgis, Feb 23, 2015.

  1. Scott Bartgis

    Scott Bartgis Member Licensed User

    Hello. First some props: I love B4A. As a .Net programmer, this was the easiest leap I have ever made.

    Here is the scenario: My company makes high-end, super expensive, Linux-based music servers. The Android app I am writing is going to control the 4 independent audio zones. The server produces realtime data on an XML socket which I have successfully implemented. This provides me with the realtime feedback of the players, time elapsed, current song details, etc.

    In the course of communicating with the server, I need to make numerous calls for "small" information. For example, if I want to know the name of the server, I need to send a request to http://192.168.10.101/ini.php?cmd=get&section=systeminfo&key=unitname

    The response will come back as a string.

    So the question: Without synchronous communication, how do I abstract a function such as GetIni(section as String, key as String) As String so that it can return to the callers who need the Ini value to make a decision?
     
  2. DonManfred

    DonManfred Expert Licensed User

    start a httputils async call and in jobdone you get the result then
     
  3. Scott Bartgis

    Scott Bartgis Member Licensed User

    That's kind of the problem in a nutshell. The response comes in whenever it comes in, but you have lost the calling function who asked the question. I understand we can't have synchronous HTTP calls and the blocking of the thread. Totally understand. Just trying to engineer a solution.

    How about this in pseudo-code:

    Class MediaServer exposes a GetIni function. The GetIni function initiates the HTTPUtils2 async call and spins/waits for the requested section/key to appear in a list maintained by the class. Then it can return. The spinwait will be timed so that it can timeout and return "" if there is no response. After retrieval from the list, the item is removed ensuring it has to be refreshed directly from the server.

    The calling function would come from an initialized construct of the MediaServer class. For example:

    Dim server as MediaServer
    server.Initialize(...) 'however i have chosen to do this
    Dim serverName As String = server.GetIni("SYSTEMINFO","UnitName")

    server.GetIni does not return until populated or timed out.
     
  4. Scott Bartgis

    Scott Bartgis Member Licensed User

    So I just figured out that this approach also won't work. The XOMBuilder_BuildDone does not fire until the GetIni function returns. I put gentle Thread sleeping into the loop, and I can see my timeout iterator incrementing. As soon as the incrementor hits the threshold, the function returns and THEN BuildDone is fired.
     
  5. warwound

    warwound Expert Licensed User

    That's the nature of asynchronous calls.

    The XOMBuilder BuildFrom??? methods allow you to pass any object/value as a Tag parameter.
    The Tag parameter is not used in the build process but simply passed back to your b4a code in the XOMBuilder BuildDone event.

    The theory is you pass a unique identifier as the Tag value and then when the BuildDone event is raised you can use the Tag value to identify which BuildFrom??? method the event relates to.

    Would that solve your problem?
     
    thedesolatesoul likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice