B4J Tutorial [Server] Data Collection Solution - Device, Desktop and Web reports

Discussion in 'B4J Tutorials' started by Erel, Jan 29, 2014.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    This is an example of building a data collection solution. The solution is made of three components:
    - (B4J) Server - Manages the data in a SQLite database.
    - (B4A) Device client and (B4J) desktop client - Send new data to the server and show reports.

    Note that you can also see the reports from any browser.

    In this example we want to track animals. The following type is declared in all three projects:
    Code:
    Type Animal (Name As String, Age As Double, Location As String, Date As Long)
    upload_2014-1-29_16-0-32.png upload_2014-1-29_16-1-10.png

    Animal objects are sent to the server. This is done with RandomAccessFile as explained here:
    Send and receive objects

    Both the server and the clients are pretty simple (check the code!).
    As we are using SQLite database we set the handlers to be single threaded and thus avoid issues with concurrent transactions.

    You can make the server accessible over the internet by following the steps described here:
    Upload files from your B4A app to your B4J server over the internet

    If you run it in the local network then you only need to open the firewall port (51042 in this example) to incoming connections.
     

    Attached Files:

    Last edited: Mar 5, 2018
    Beja, MarkusR, luke2012 and 4 others like this.
  2. JOTHA

    JOTHA Well-Known Member Licensed User

    I did everything described above and also told the firewall to open the port 51042, but it doesn't work. Here is the message:
    Connection to http://192.168.0.100:51042 refused
    I'm confused.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
  4. JOTHA

    JOTHA Well-Known Member Licensed User

    Done.
    Thank you Erel!
     
  5. sap

    sap Member Licensed User

    hello Erel
    the example works well is to select a command line in the webview to simply remove and empty the database you is it possible to support me

    thank you
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You can add a new handler in the server project that deletes the data you need.
     
  7. sap

    sap Member Licensed User

    [Quote = "Erel, poste: 231375, membre: 1"]. Vous pouvez ajouter un nouveau gestionnaire dans le projet de serveur qui supprime les données dont vous avez besoin [/ quote]


    hello
    exist there examples because my project is to add functions in DataCollectionDesktop (delete, Were)
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    In this example the data is not stored in the desktop. It is stored in the server. This means that you will need to send a command with HttpUtils2 to the server which will then delete the data.
     
  9. sap

    sap Member Licensed User

    [Quote = "Erel, poste: 231693, membre: 1"] Dans cet exemple, les données ne sont pas stockées dans le bureau. Elle est stockée dans le serveur. Cela signifie que vous aurez besoin d'envoyer une commande avec HttpUtils2 au serveur qui sera ensuite supprimer les données. [/ Quote]


    Merci Erel
     
  10. sap

    sap Member Licensed User

    t [quote = "Erel, poste: 231693, membre: 1"] Dans cet exemple, les données ne sont pas stockées dans le bureau. Elle est stockée dans le serveur. Cela signifie que vous aurez besoin d'envoyer une commande wi h HttpUtils2 au serveur qui sera ensuite supprimer les données. [/ quote]


    Mobile I wanted to send to the server located on the local network pc in an application to retrieve the desired data (=?) on my mobile

    is it possible to have an example

    thank you
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    This example calls the local server and adds data or returns the available data.
     
  12. masmukti

    masmukti Member Licensed User

    hello Erel. I am new here, how to display images from SQL BLOB to HTML in an application server? Untitled.png
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    masmukti likes this.
  14. masmukti

    masmukti Member Licensed User

    great !!
    done ,
    thanks Erel..
    Untitled2.png
     
    luke2012 and Erel like this.
  15. delozoya

    delozoya Member Licensed User

    Hello. apart the view the database in webview in app Desktop. I can send the database in server to Desktop?
     
  16. luke2012

    luke2012 Well-Known Member Licensed User

    Hi @Erel,
    I need to retreive a record passing the record ID in order to retreive the related name (I have an ID and Name fields).
    So I have to create an handler (like /report example) in order to retreive the requested data.

    In the example (/report handler) the caller job doesn't pass any parameter (request) and the handler execute a "select * ..." query in order to retreive the data.

    My target is to pass a parameter (ID) to the request in order to execute a query using the id as where condition.
    How do this using http job object ?
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Passing "GET" parameters is very simple.

    You add the parameters to the link:
    http://example.com/report?key1=value1&key2=value2

    In the server you can get the parameters with:
    Code:
    req.GetParameter("key1")
    Note that it is better to use HttpJob.Download2 to build the link.
     
    luke2012 likes this.
  18. luke2012

    luke2012 Well-Known Member Licensed User

    @Erel first of all, thanks for your fast and useful reply!
    Another little question :)

    Within the the class handler, how I can manage the SQLite constraints violations (ex. unique constraint raised by the db engine) in order to advice the user and handle the event in the client (app) ?
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    I don't remember all of the details of this example, however you can return any information you like from the handler.

    For errors you should usually use resp.SetError(500, "error message").

    This way HttpJob.Success will be false.
     
    luke2012 likes this.
  20. TAK

    TAK Member Licensed User

    Hi,
    what kind of connection is it? Http or a mixure of several?
     
Thread Status:
Not open for further replies.
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