Android Tutorial [B4X] CloudKVS - synchronized key / value store

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @Erel,
when the server is up all work fine.

But sometimes the server is not available (down or not in wifi range) and I have an app crash with the following error:

"Error sending task: java.io.InterruptedIOException: timeout" (please see the attached log)

Is it possible to allow user to use App also without a server connection using the local App data?

Thanks in advance for your reply.
 

Attachments

  • log_Error_sending_task.txt
    5.4 KB · Views: 460

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is it possible to allow user to use App also without a server connection using the local App data?
Yes. This is the most important feature of CloudKVS.

Which version of B4A are you using? Have you modified the code in ClientKVS example? Are you running it in Release (obfuscation) mode?
 

luke2012

Well-Known Member
Licensed User
Longtime User
1) B4A: I'm using B4A version: 6.00
2) ClientKVS: yes, but only for add my app code without modify the CloudKVS core code (main & class).
3) Compile mode: yes I'm running in Release (obfuscation) mode
4) I have duplicated (copy, paste and renamed) the project folder starting from the original ClientKVS sample project and than I customized it
 
Last edited:

JakeBullet70

Well-Known Member
Licensed User
Longtime User
My little addition to the ClientKVS.bas file.
Took me like 5 minutes to figure out that to delete a key you use the 'put' function with Null... LOL

B4X:
Public Sub Delete(User As String, key As String)
    Put(User,key,Null)
End Sub
 

luke2012

Well-Known Member
Licensed User
Longtime User
@Erel I have a couple of questions about CloudKVS Server:

1) How to known (programmatically within the client app) if a CloudKVS Client is disconnected from the CloudKVS Server?
2) In this specific case (CloudKVS Server) is it better to distribute the Server using the B4J Packager or only the server .jar executable file?

Thanks in advance for your reply.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. The clients do not maintain an active connection to the server. The clients connect to the server when needed and then disconnect. Job.Success will be false (in JobDone) if it is unable to connect.

2. It is better to distribute the executable jar. The executable is cross platform compatible and doesn't require installation.
 

luke2012

Well-Known Member
Licensed User
Longtime User

2. The minimun requirement is JAVA jre 8 on the server machine right?
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @Erel
Is it possible to access the keys about new items (runtime object that contains the new data) within the "ckvs_NewData" event?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the code that inserts the new data to the local database (ser_BytesToObject):
B4X:
If Success Then
     Dim items As List = NewObject
     If items.Size > 0 Then
       For Each item1 As Item In items
         InsertItemIntoData(item1, True)
       Next
       sql.ExecNonQueryBatch("getuser")
     End If
You can modify this code and raise another event with the the list of keys (or list of items). Do note that the items were not yet added to the database at this point.

A simpler option is to just get the keys that you are interested in again.
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @Erel,
it is possible to know (progammatically) if a new putted KVSCloud item has been synchronized or not?

Thanks in advance for your reply.
 

luke2012

Well-Known Member
Licensed User
Longtime User
DeleteFromQueue is called for each item that was uploaded successfully to the server.

You can get the user and key from the queue table at that point and raise an "ItemWasUploaded (User As String, Key As String)" event.

OK @Erel. I'll check this.

Last thing about Cloud Sync.
Sometime I read this error within the log:

"Error sending task: java.net.SocketTimeoutException: failed to connect to /192.168.0.10 (port 51042) after 30000ms" *

*Where 192.168.0.10 is my server (Cloud) machine

Is there any way to intercept this error and in order to notify the user about the Server connection problem ?
 

miquelr

Member
Licensed User
Longtime User
Hi Erel,
I'm developing an aplicación in B4A with a number of 'activitys'. After add ClientKVS, CallSubUtils and Starter (as is in your example ) -- with kvsCfgMap = Starter.ckvs.GetDefaultAndPut (user, "kvscfgmap" kvsCfgMap) in Main ---, when I switch to another 'activity' (with callSubDelayed2 ...) appears the new activity but in some seconds Main reappears.

I've tried to change in Starter module without success:

Sub ckvs_NewData
' CallSubDelayed(Main, "ckvs_NewData")
' CallSubDelayed(SWUtils, "ckvs_NewData")
SWUtils.ckvs_NewData '
End Sub
SWUtils is a code module with a sub ckvs_NewData
I need your assistance
Miquel
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…