Ask Question, Ask an Expert

+1-415-315-9853

info@mywordsolution.com

Ask Programming Language Expert

Introduction

Dropbox is a service that permits a user to save files onto their server, and automatically synchronize the files between the server and a number of devices comprising computers, phones, and tablets. The user installs client software onto their computer, and the client software takes care of automatically synchronizing files between client and server.

Your task in this assignment is to apply a simple version of Dropbox, using the file, socket and select system calls. While you may find it interesting to read more about Dropbox itself, the specifications in this document describe your task for assignment. Dbclient
When the dbclient is run, it will first establish a socket connection to dbserver, and will send a message having the userid, and the name of the directory that the client wants to synchronize. We will restrict synchronization to files in one directory and will not handle subdirectories. Every N seconds, client will initiate a synchronization operation.

A synchronization operation uses the subsequent algorithm:

For every file in the local directory get the last modified time and size send a sync_message request to the server containing the filename, last modified time, and size. Read a sync_message response from server having filename, the server's last modified time for the file, and size of the file on the server. If the last modified time in message from server is more recent that the local last modified time the client will read the file from server one CHUNKSIZE chunk at a time and will replace the local file with the contents from the server. Or else, the client will send the local file one CHUNKSIZE chunk at a time to the server. After iterating over all files in the local directory, the client checks to see if the server has any new files to send by sending an "empty" sync_message (a message with an empty string for the file name, a last modified time of 0, and a size of 0). It reads the response message from the server. If the server's response message is also an empty message, then client knows there are no new files.

If the server's response message has a non-empty file name, a non-zero last modified time, then the client will read file from the server as above. After it has completed reading file, it will repeat the procedure of sending a new file request (by sending an empty sync_message) and reading new files from server till it receives an empty message from the server.

dbserver

The server is a little more difficult. It will generate a directory for each user under the directory name provided by user. If two users use the same directory name, we will assume they are sharing the directory.

Since the server is maintaining multiple connections, we do not want the server to block on a read or accept from any client. To solve this problem, we will employ select to multiplex between clients. This also means that we will need to keep track of the type of message that the server anticipates to receive from a client depending on state of the client. When the server is notified (via select), that a message is accessible to read from the client, there are several possible options. The server may be expecting a login_message, if it hasn't read anything from the client yet.

A CHUNKSIZE chunk of a file, if server has realized that a file is newer on client than on server. A sync_message, otherwise, the server will store the following information for each client:

- The user id of the client
- The socket files descriptor
- The directory name where the client's files are stored
- A list of the files that the client has synchronized with server. Information about each file includes:
- The file name
- The last modified time sent by the client.

A partial algorithm that describes the communication between the server and a single client follows. Note that the server only acts in response to a message from the client. Apart from the initial setup, it does not initiate any operations. Handle a read from a client

case LOGIN:
        read login message and store userid and dir in client array
        create dir if doesn't exist
        set state = SYNC
    case SYNC:
        read sync_message
        if sync_message is an empty message
            figure out how to identify a file on the server that is not on
            the client, and add it to the client list
        else
            find filename in client's files array
           
        prepare response (if there are no new files to send, then send an empty response)
        if file's mtime is newer in clients' files array on server than in sync_message
            prepare file to client
            set state = SYNC
        else
            set state GETFILE
            (keep track of which file we are expecting to read)
    case GETFILE:
        read chunk
        prepare chunk
        if finished reading file (keep track of size vs bytes read)
            set state SYNC

Part of algorithm is missing. In particular, the server needs to handle an empty sync_message from the client which is an indication that the client is checking if the server has a file that the client does not. You will need to figure out a strategy to identify the files that the server is storing in the appropriate directory that are not in the client's list of files, so that they can be added to the client's list.

Tips:

Take advantage of the ex code shown in class and given on the course web site. The ex code will help you set up the sockets and the select call.

prepare the code incrementally. Make sure each step compiles and runs before moving on. It will save you time!! The first step might be to prepare a client that just sends the login message, and the server that receives only the login message a store’s the client info. An intermediate step might be one where no file data is transferred, but the sync_messages are sent. prepare and test a function that fills in a sync_message for a file.

Note that we have taken lots of shortcuts with the starter code. In particular, the number of clients and the number of files are artificially limited. I would not prepare production code this way, but it simplifies this part of the assignment.

Also note that we don't allow file deletion on the server. Once a file has been synchronized to the server, it stays there.
Be careful to handle the case where a client connection is closed.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91485

Have any Question? 


Related Questions in Programming Language

Question 1what is overriding please use code to explain it

Question 1: What is overriding? Please use code to explain it. (Cannot use the same code in class) Question 2: What are the benefits when inheritance is used if multiple classes share the same fields and methods? Questio ...

Design an abstract class called shape this class must

Design an abstract class called Shape. This class must contain a single constructor that accepts a single numeric value that can be used to calculate various values, one of which is area. Include an abstract method calle ...

The concepts discussed in this section can also be applied

The concepts discussed in this section can also be applied to eliminate partially dead code. A definition of a variable is partial ly dead if the variable is live on some paths and not others. We can optimize the program ...

Suppose you have a class cbirdsuppose you have a class

Suppose you have a class CBird Suppose you have a class CBird, as follows, that you want to use as a base class for deriving a hierarchy of bird classes: class CBird { protected: int wingSpan; int eggSize; int airSpeed; ...

Contact list project where the user enters first name last

Contact list project where The user enters first name, last name, street address, email address, phone number and notes. Use Case Name: Enter a new person ID number: 1 Actors: user Preconditions: The user has chosen to e ...

Derive a class programmer from employee supply a

Derive a class Programmer from Employee. Supply a constructor Programmer Exercise 1: Derive a class Programmer from Employee. Supply a constructor Programmer (string name, double salary) that calls the base-class constru ...

Programming assignmentthis question has two parts a and

Programming Assignment This question has two parts (a) and (b): Develop a program to read in five exam-scores (in the range of 0-100) of a student in HIST220 class. (a) You program should compute and store in memory the ...

Write a program that prompts the user to enter length and

Write a program that prompts the user to enter length and width dimensions for each room in a proposed house so that total floor space can be calculated for the entire house. After each length/width entry, ask the user i ...

Generate code for the following three-address statements

Generate code for the following three-address statements assuming stack allocation where register SP points to the top of the stack. call p call q return call r return return

Assignment testing and quality assurancenote this is part

Assignment: Testing and Quality Assurance Note: This is part three of a four-part implementation plan that will be combined to form the finalized plan in Week Four. It is expected that adjustments will be made in the fin ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro

Describe what you learned about the impact of economic

Describe what you learned about the impact of economic, social, and demographic trends affecting the US labor environmen