Sync Resources

http://codeoncloud.blogspot.com/2013/07/android-mysql-php-json-tutorial.html

http://codeoncloud.blogspot.com/2013/07/android-web-service-access-using-async.html

http://codeoncloud.blogspot.com/2013/06/android-java-soap-web-service-access.html

http://coenraets.org/blog/2012/05/simple-offline-data-synchronization-for-mobile-web-and-phonegap-applications/

http://www.techchorus.net/xml-rpc-server-and-client-php-determine-clients-ip-address

http://appSync.org

 

 

Sync JSON-PHP

Just follow some steps for sending data from Android to MySQL:

  1. Create JSON object of your data using JSONObject and JSONArray class.
  2. post that as an string to your Web Service that might be in PHP or whatever you prefered.
  3. process to parse json and insert data in to MySQL database.

Same as from MySQL to Android:

  1. Create Web Service that displays your data in JSON Format.
  2. then you have to Request to that link and you’ll get JSON data, just you have to parse and store into SQLite.

You have to take care about Data Confiction. for that you have to take one that store some value both side likelast sync date/time.

There are some tutorial that will help for android JSON Parsing and PHP JSON Parsing.

  1. For Android
  2. For PHP

Asynchronous vs. Synchronous Web Services

Synchronous communication is direct communication where the communicators are time synchronized. This means that all parties involved in the communication are present at the same time. This includes, but is not limited to, a telephone conversation (not texting), a company board meeting, a chat room event and instant messaging.

Asynchronous communication does not require that all parties involved in the communication to be present at the same time. Some examples are e-mail messages, discussion boards, blogging, and text messaging over cell phones. In distance (specifically online) education asynchronous communication is the major (sometimes the only) method of communication. Usually, we use different discussion boards in each class with each having its own purpose.

e.g. synchronous

When I call you on the phone, I dial your number and WAIT until you pick up. Then you say something, and in the very same moment I listen to you. When you finished, I send you data (talk to you) and in the same moment you receive them (listen to me). At the end of our communication one of us says “END OF TRANSMISSION” (Good Bye), the other says “Acknoledged” (Good Bye) and then both ring off.

asynchronous

I write you a letter. I put it to the postoffice, and it will be sent to you. I the meantime I do NOT WAIT. I do many different other things. Then you receive the letter. You read it while I still do many different other things. Then you write me an answer and send it to me. In all those things I am not involved. At the next day I get a (synchronous) message (a signal) from the system (postman). It (he) says: “Here is a message for you”. Alternatively I could poll my inbox every five minutes to check if a new letter is there. Then I pause my other work, receive your letter and read your answer. Then I do something according to this answer. But this are things you will not notice, because you are not involved in what I do with your asynchronous answer.

http://stackoverflow.com/questions/17872854/synchronous-vs-asynchronous-related-to-web-services

Facts to build own sync

If you write this yourself these are some of the points to keep in mind

  • Proper authentication between the device and the Sync Server
  • A sync protocol between the device and the server. It will usually go in 3 phases, authentication, data exchange, status exchange (which operations worked and which failed)
  • Pick your payload format. I suggest SyncML based XML mixed with JSON based format to represent the actual data. So SyncML for the protocol, and JSON for the actual data being exchanged
  • Keeping track of data changes on both client and server. You can maintain a changelog of ids that change and pick them up during a sync session. Also, clear the changelog as the objects are successfully synchronized
  • Need to have a way to communicate from the server to the device to start a sync session as data changes on the server. You can use C2DM or write your own persistent tcp based communication. The tcp approach is a lot seamless
  • A way to replicate data changes across multiple devices
  • And last but not the least, a way to detect and handle conflicts
  • To make data exchange, web server needs to provide RESTful web services (json, xml, etc) then mobile can receive data.

REST

REST is 

Representational state transfer.  REST-style architectures conventionally consist of clients and servers.

RESTful web API HTTP methods

Resource 1: http://example.com/resources

PUT:Replace the entire collection with another collection.

POST: Create a new entry in the collection. The new entry’s URI is assigned automatically and is usually returned by the operation.

Resource 2:http://example.com/resources/item17

PUT:Replace the addressed member of the collection, or if it doesn’t exist, createit.

POST:Not generally used. Treat the addressed member as a collection in its own right and create a new entry in it. 

 

 

Put vs Post (REST)

Both are used to create.

FROM : http://stackoverflow.com/questions/630453/put-vs-post-in-rest

POST:

Used to modify and update a resource

POST /questions/<existing_question> HTTP/1.1
Host: wahteverblahblah.com

Note that the following is an error:

POST /questions/<new_question> HTTP/1.1
Host: wahteverblahblah.com

If the URL is not yet created, you should not be using POST to create it while specyfing the name. This should result in a ‘resource not found’ error because <new_question> does not exist yet. You should PUT the resource on the server first.

You could though do something like this to create a resources using POST:

POST /questions HTTP/1.1
Host: wahteverblahblah.com

Note that in this case the resource name is not specified, the new objects URL path would be returned to you.

PUT:

Used to create a resource, or overwrite it. While you specify the resources new URL.

For a new resource:

PUT /questions/<new_question> HTTP/1.1
Host: wahteverblahblah.com

To overwrite an existing resource:

PUT /questions/<existing_question> HTTP/1.1
Host: wahteverblahblah.com