In server Synchronization module both Servers open two sockets named Slave and Master. A list of files is maintained on both servers with last modified time which can be sent and compared to get the latest file. A deleted file list is maintained on both sides whenever other server stops working this list is shared to handle deleted file synchronization. Master Sockets waits for slave request from other server. When request comes on Master socket it identifies the request as if Request is Client_Liast then send the list of all the files with file name and timestamp, if Request is Sync_Delete file list then send number of files deleted with names, and if Request is File_Request, Send the requested filename with data. This process is repeated between both servers after every 5 sec delay.
Server-to-Server Communication Implementation
Algorithm:
1. OPEN SYNC MASTER SOCKET (TCP SERVER)
2. SCAN DB and CREATE FILE LIST
3. ACCEPT SLAVE CONNECTION
4. CHECK SLAVE REQUEST
5. IF REQUEST == SYNC_CLIEN_LIST_REQUEST
THEN
REPLY NUMBER OF FILES from DB sends each file name and timestamp
6. IF REQUEST == SYNC_DEL_FILE_LIST_REQUEST
THEN
REPLY NO. OF FILES DELETED
FOR LIST OF FILES SEND EACH FILE NAME
7. IF REQUEST == FILE_REQUEST
IF REQUEST SUBTYPE == GET
- READ FILE GET SIZE OF FILE
- SEND FILE SIZE AND START REPLY
- SEND THE FILE
8. IF REPLY SUBTYPE == PUSH
-READ THE FILE SIZE
-RECEIVE FILE IN BUFFER
-STORE THE FILE
9. SYNC_SLAVE_THREAD
-CONNECT TO MASTER
-CLEAR GET & PUSH FILE LIST
-SEND DEL_FILE_LIST_REQUEST
RECEIVE NO OF DELETED FILES WHEN IT WAS DOWN
GET THE FILE NAMES
REMOVE THE FILES
10. SEND SYNC_CLIENT_REQUEST
-RECEIVE NO. OF FILES
-RECEIVE EACH FILE NAME AND TIMESTAMP
-CREATE A LIST OF FILES CONTAINED ON MASTER
11. COMPARE TIMPE_STAMP OF EACH FILE WITH MASTER & SLAVE
12. FORM GET FILE LIST
13. FORM PUSH FILE LIST
14. SEND REQUEST FOR GET FILES
-RECEIVE THOSE FILES AND STORE IN DB
15. SEND REQUEST FOR PUSH FILES
-SEND EACH FILE TO MASTER
16. CLOSE SOCKET
17. FOR RE-INITIATION GO TO STEP 1 AFTER 5 SEC DELAY