I suppose you understand that this is not a trivial problem. I wrote a library to accomplish this for a commercial application last year, and it took about 6 months to get it to where I was pleased with it.
Leaving aside the argument of using ports 80 and HTTP (TCP / IP) to avoid problems with the firewall and support, you need to develop a protocol. Since my project was very intuitive, I went with a binary protocol (and not a bloated xml) that could handle any data. I also wanted it to be bi-directional so that I could insert INSERT data as well as fulfill queries. I used CGI / FastCGI on the server.
The binary protocol I developed is pretty simple (always better) and breaks large transfers into pieces of a user-defined size (about 600K seems good). Each piece has a header followed by data.
Although this protocol can be used to transfer any kind of data, it is usually used for database style data, as your question suggests. To do this, I decided to use a line / column design approach. The data is stored in one row at a time, each of the columns is stored for the first row, then all the columns for row 2 ... row n.
Single Column Data Format:
' Col1Type 1Bytes - BYTE ' Data Type (REMSQL_TEXT etc) ' Col1Len 4Bytes - DWORD ' Length in bytes the Column Data - up to 4.2GB ' Col1Data nBytes - BYTE ' String data
(in C, BYTE - CHAR)
This means that each column has a data type descriptor. All data types can be represented:
REMSQL_NONE = 0 ' DataType undefined REMSQL_QUAD = 1 ' 64-bit signed integer REMSQL_DBLE = 2 ' 64-bit IEEE floating point number REMSQL_TEXT = 3 ' STRING - (CHAR) string of Ascii Bytes REMSQL_BLOB = 4 ' BLOB - (CHAR) string of Binary Bytes REMSQL_NULL = 5 ' NULL - Empty Column
These data types are the same as the basic SQLite data types and are numerically equivalent to listing the fundamental SQL3 data.
In this project, if the field is empty (NULL), you saved only 5 bytes. If the field has 200 bytes of text, for example, only 205 bytes are required to store it. The biggest advantage is data analysis, because you can skip columns without reading all 200 bytes to find some kind of trailing character.
The Chunk header should contain things like number of rows, number of columns, total number of bytes, etc. If you use DWORD (unsigned integers), the theoretical limit for a chunk is 4.2gigs, which should be sufficient even for a local tranmission network.
To implement this function, you need to write SQLite / MYSQL covers. I use only the BINARY protocol, which takes a little time, but you need the following functions: Client side: SendRequest () - sends a request, waits for a response
Server side: ProcessRequest () - receives a request, processes and returns a response
In my case, the answer may be! 00MB of data or more. I retrieve the entire dataset from MySQL and save it to disk on the server. Then I return an empty piece that contains the dataset metrics. Then the client requests a data set in pieces of 600 thousand, one by one. If the connection is lost, it simply rises where it stopped.
Finally, the data set was mostly textual (address names, etc.), so it was ripe for compression. Security was a very big problem in this case, so encryption was necessary. This gets a little complicated for implementation, but basically you compress the entire fragment, pad, to a length that is a multiple of the BLOCKSIZE block ciphers and encrypts it.
In the process of all this, I write a very fast class of line builders, implementation of AES encryption in ASM and the entire FastCGI library (www.coastrd.com)
So, as I said, non-trivial. I will make this library available soon. If you want to check it out, write to me.
After you write a message, you can begin to develop synchronization. I would either use a hash for each entry, or a simple boolean flag. If something changes on the server, just send the entire record and overwrite it on the client side (provided that you are trying to synchronize the clients ...)
If you write your own, please write here about your experience!
PS. Consider changing the name to be more search friendly. Maybe something like:
"Synchronizing the SQLite Client Database with the MySQL Server Database"