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

Status
Not open for further replies.

delozoya

Member
Licensed User
Longtime User
There is no persistent connection here. It is a standard http server.

ok, but when you spend 10 seconds without connection, then no receipt or sending data. if they are only five seconds, so if you send or receive data.
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hi Erel,
I try to run the sample but returns the error of the picture.
HelloWorld example works.
what is wrong?
 

Attachments

  • Error.png
    32.6 KB · Views: 481

billzhan

Active Member
Licensed User
Longtime User
Start the jar with command line, see what' in logs:
B4X:
java -jar DataCollectionServer.jar
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
thanks for reply billzhan
but it still does not work!?!
looks picture.
thank you
 

Attachments

  • error.png
    40.1 KB · Views: 439

billzhan

Active Member
Licensed User
Longtime User
I see the jar size is small.So libs are not merged to the jar. #MergeLibraries: True

B4X:
#Region  Project Attributes
   ...
    #MergeLibraries: True
 
#End Region
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
fantastic! works .... thanks a lot.
also can you tell me which jar should I use to connect to a sql db?

P.S. as a system to send data to the server seems slower RemoteDataConnector or am I wrong?
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
excuse me if I make another request!
how do I make me return a field map from the server to update the DB client B4A?
thanks in advance
 

billzhan

Active Member
Licensed User
Longtime User
Not sure that I understand properly.

The demo is based on sqlite, I you want to use other dbs,you can use jsql(download and set up with different jdbc drivers) https://www.b4x.com/android/forum/threads/sql-tutorial.35185/

Note that in this demo, sqlite and threads is set for single thread mode.
B4X:
 srvr.AddHandler("/AddAnimal", "AddAnimal", True)  'True for single thread mode
If you want it work with high concurrent connections see: https://www.b4x.com/android/forum/threads/server-building-web-servers-with-b4j.37172/#content.
Tests show that performance of sqlite (set to Wal mode) will be much more better with SSD . https://www.b4x.com/android/forum/threads/server-performance-measures.37502/
I've not compare it with RDC.

If you want server return a map to client(b4a), you can generate json string of the map, send the json string to client.

B4X:
Public Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim anml As Animal = Main.ReadObject(req.InputStream)
    Dim m As Map
    m.Initialize
    m.Put("Name", anml.Name)
    m.Put("Age", anml.Age)
    m.Put("Date", DateTime.Date(anml.Date))
    m.Put("Location", anml.Location)
    DBUtils.InsertMaps(Main.SQL1, "Animals", Array As Object(m))
   
   
    Dim resMap As Map=CreateMap("time":DateTime.Now)
    Dim j As JSONGenerator
    j.Initialize(resMap)
    resp.Write(j.ToString)
   
    'resp.Write("Animal added successfully.")
   
   
End Sub


'client parse the returned json string
Sub JobDone(j As HttpJob)
    If j.Success Then
       
        If j.JobName = "yourjobname" Then
            Dim jsonstring As String=j.GetString
            Dim jp As JSONParser
            jp.Initialize(jsonstring)
            ...
        End If
   
    ...
end sub
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
what's the best way to send parameters to the server when sending object?

Sub SendObject (Obj As Object)

raf.WriteObject (Obj, True, 0)
Dim size As Int = raf.CurrentPosition
Dim data (size) As Byte
raf.CurrentPosition = 0
Do While raf.CurrentPosition <size
raf.ReadBytes (date, raf.CurrentPosition, size - raf.CurrentPosition, _
raf.CurrentPosition)
loop
Dim j As HttpJob
j.Initialize ("send object", Me)
j.PostBytes (link & "/ AddAnimal", data)
end Sub
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
clear, thanks Erel
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
is interesting log that records transactions.
Can I add other customized information?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…