Android Question db SQLite synchronization between devices

LucaMs

Expert
Licensed User
Longtime User
Hi.

I'm "new" and sorry for my english: i used a translator.

I would have so many questions to ask (unfortunately), and in return, I hope I can help someone and maybe post code useful to the community.

Given that I have searched on the site, I have not found an optimal response and final.

What I would get is "simply" data synchronization (db SQLite) in my app installed on two smartphones, without the web, cloud or other "obscurity".

Clearly, despite the existence of WiFi, BlueTooth and NFC, I guess the most common is BT.

In short, how to implement it? Is there any library / class already ready-made (both as a medium of exchange such data. BT but also for tables and fields).

Obviously, it is not ONLY laziness, my, but the need to shorten the development time.

Thank you in advance and good job to all.
 

Mahares

Expert
Licensed User
Longtime User
The following link allows you to pair 2 devices together via BT or WiFi as well illustrated by Erel's fine example. You can transfer files between 2 smartphones. You will need the RandomeAccess lib 1.6 in internal lib folder. Hopefully this can put you toward the solution you are seeking where you can share database files between the paired devices.
http://www.b4x.com/android/forum/th...eceive-files-with-asyncstreams.30493/#content
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The following link allows you to pair 2 devices together via BT or WiFi as well illustrated by Erel's fine example. You can transfer files between 2 smartphones. You will need the RandomeAccess lib 1.6 in internal lib folder. Hopefully this can put you toward the solution you are seeking where you can share database files between the paired devices.
http://www.b4x.com/android/forum/th...eceive-files-with-asyncstreams.30493/#content


I will try to follow your suggestion. Thank you, Mahares.
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Hello, Luca.
Hello, Mahares.

Since you referred to FileTransfer (indeed Erel's fine example), maybe you could take a look at my post here

Any help is welcomed.

Thank you,

Sandy

PS: I am also thinking of db sync among two to four Android devices (1 "server" and 1 to 3 "clients". I tried and liked RDC (also Erel's fine adaption to B4A), but I want to stay in a pure Android environment (too bad RDC "server" does not exist in Android). BT is much slower than WiFi, in my testing results with FileTransfer.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
File transfer mechanism is actually independent of the communication/connection tool.
Once you created a connection (WiFi, BT, WiFiDirect - all in the forum by Erel) you can define the AsyncStreams connection and transfer files.
AsyncStreams can be used only one-to-one.
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, and Shalom, David.

I understand that the connection (my interest is primarily in WiFi) is in the Network Library and the AsyncStreams is part of the Random Access Library. Both libraries stretch my technical skills since I have very little experience in these areas.

Question:
Is there a way to know the IP address of the tablet (the sender) connected to the "server" tablet (the receiver)? I know Socket.ResolveHost is deprecated.

Best regards.

Sandy

PS:
RUN MULTIPLE AsyncStreams IN ONE DEVICE
I duplicated Erel's FileTransfer app, gave it a new package name FileTransfer2, changed the port, and then:
Device A ("server") running FT and FT2
Device B running FT - connected to Device A and transferred a large file successfully.
Device C running FT2 - connected to Device A and simultaneously transferred a large file successfully.
Not elegant, but it worked....
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Is there a way to know the IP address of the tablet (the sender) connected to the "server" tablet (the receiver)? I know Socket.ResolveHost is deprecated.
Seems no, but you can send it as a message from the sender to the server.
AsyncStreams is using RandomAccess, it is not part of it.
You can run multiple Astreams in one device but the transfer of data using it is still with one device per each Astreams connection.
 
Last edited:
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Thanks again, David.

I thought of making the IP of the sender as a "prefix" to the filename...

The question for me, because I am truly a novice in this area, is:
How can I run multiple Astreams in one Service module using each a different port? Multiple server sockets would be needed??? And then the "client devices" would be assigned a socket to establish the connection???? :confused:

Shalom,

Sandy
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
If you're using sockets, you need to have a server socket which listens for connections.
When a client connects to the server socket, this new connection will create a new socket. This way a server can 'serve' multiple clients. The server has to maintain a pool of sockets, each one connected to a client. The requests coming from the clients will rise some events which will perform the actions your program needs (transfer a file, for example).
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Grazie, Straker.

Let me see if I got this straight.

Quote from B4A XML:
The ServerSocket object allows other machines to connect to this machine.
The ServerSocket listens to a specific port. Once a connection arrives, the NewConnection event is raised with a Socket object.
This Socket object should be used to communicate with this client.
You may call Listen again and receive more connections. A single ServerSocket can handle many connections.
For each connection there should be one Socket object.

I can read it; understand it; Code it?????

Is there an example in the forum for single Server socket and multiple clients or connections (sockets)?

Migliori saluti,

Sandy
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I guess using a class for each connection is an 'elegant' way.

I don't agree because usually any client ("connection") should have the same functionalities, so you should have just one class module with its socket and a map variable that contains each class instance (with events).

The question is:

what exactly tdocs2 wants to achieve?

there are so many examples about sockets and web sockets on site.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I don't agree because usually any client ("connection") should have the same functionalities, so you should have just one class module with its socket and a map variable that contains each class instance (with events).

The question is:

what exactly tdocs2 wants to achieve?

there are so many examples about sockets and web sockets on site.
I have a server using a class for multiple connections. At what exactly don't you agree?
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
I guess using a class for each connection is an 'elegant' way.

Hello, mc and Luca, and thank you.

Where in the forum could I see an example of this? I have looked at Erel's FileTransfer and could not figure out how to make it into a class or even a multi socket app (I was going to try this next). All the comments have helped me gain a better understanding. It is easier for me to follow an example - as I guess it is for most people.

I can read it; understand it; Code it?????

Luca, Related to your question what I am trying to do is "sync" a DB residing on a "server" tablet when one to three clients take a specific action (similar to your post #1 in this thread). My sync is very easy - from the "server' send the complete data base to the "client" who is requesting a sync or has performed an update sent to the server (only 2 types of update and volume is low - 20 to 40 updates per day from all clients). The DB itself I have created to test simulates a ten year history with 60,000 records - around 4MB - and it takes less than 4 seconds to send and receive using Erel's File Transfer as the app and a Netgear 750 wireless router.

Once again, thank you both for your generosity and your feedback.

Sandy
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
That was probably my first post on this site :).

The good news is that... I've abandoned that idea, too much difficulty.

You can send an entire database from a client to a server or vice versa, but the data will not be "consistent".

The only way is to have one centralized db on the server (and, in this case, you can create a server in b4j).

Right now I'm getting a question:
b4j servers should also work on Android systems.
But I fear that in this case you should have a rooted device.
Well, this is a question to be submitted to Erel.

Ops, he's online right now... then i'll wait for a better answer by him. :D


[P.S. probably you could follow this example]
 
Last edited:
Upvote 0
Top