Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am kind of new to the C++ language and I am having a bit of trouble starting off these programs. Assignment One program will

I am kind of new to the C++ language and I am having a bit of trouble starting off these programs.

Assignment

One program will be the update server and the other will be the update client. Here is how the two programs should interact with each other:

Server

1. the server starts up and reads the version number in the data.bin file and stores it in memory.

2. The server binds to a port and awaits connections.

Client

1. The client starts up and it will first read the version number found within it's own data.bin file.

2. The client will contact the server.

Server

1. The server accepts the incoming connection.

2. Waits for data to be sent.

Client

1. Send to the server, the integer 1. the integer 1 is code that represents a request for the current version number.

2. Wait for a reply from the server.

Server

1. Receive the request from the client.

2. See what the client is requesting. If the integer 1 was received, then the request is for the version number.

3. Send the version number back to the client

4. Close the current connection and wait for a new connection from a new client.

Client

1. Receive the version number from server.

2. Compare received version number to the client's version number.

3. If the version numbers match, then the program proceeds with it's normal operation (see below)

  • If the version numbers don't match:
    • Contact the server (again)

Server

1. Server accepts incoming connection

2. Waits for data to be sent.

Client

1. Send to the server, the integer 2. the integer 2 is code that represents a request for the updated file.

Server

1. Receive the request.

2. See what the client is requesting. If the integer 2 was received, then the request is for the updated file.

3. Open data.bin file

4. Read bytes from the file

5. Send bytes to client

6. Close the current connection and wait for a new connection from a new client

Client

1. Receive the bytes from the server.

2. Open the data.bin file for writing (this action should delete the existing file and then open a new one, ready to write data into).

3. Write the bytes received into the data.bin file.

4. Close the file

5. Proceed with normal operation

once the server has handled a request (either for the version number or for the updated file), it closes the connection and goes back to waiting for a new one.

the server will also display results to the screen to show what's happening. The client program also displays status messages to let the user know what's going on.

Client Normal Operation

This client program simpy adds two numbers together and prints the sum to the screen. The numbers that should be added, are stored in the data.bin file. The data.bin contains three numbers in this order: version, number1, number2. No spaces, line breaks, or any other seperator between the three integers .

1. Cache Requirement: The server is required to cache the version number of the data file. This means that the server should only read the version number from the data file once and store it in a variable in memory. It should NOT read the version number from the data file everytime a request is made for the version number. This is done to improve speed, since it is faster to read a value from a variable than it is to read a value from a file.

2. Server "Hot Swap" Requirement: In order to make the data file easier to swap out with new versions, the server does not need to be shut down and restarted. Instead, after every 5 requests handled by the server, it should re-read the version number from the data file. By doing this, the data file can be swapped out between client requests. Ideally, the number "5" should probably be higher in a production server, to benefit more from the cache feature, but we will use 5 for testing purposes.

3. Separate Requests: If the client's data file needs to be updated, the client is required to make TWO INDEPENDENT REQUESTS to the server.The first request is for the version number, and the second request is for the data file. The second request should send the contents of the entire data file -- including the version number again. Don't assume the client will use the previously sent version number ---- it's possible that it could have changed.

here is a little demonstration of the update server and the update client.

This is the update server after being executed in the command prompt:

Update server Current data file version: v1 Running on port number 50000

Waiting for connections... Connection received Request for current version number: v1 Connection closed Total requests handled : 1

This is the update client after being executed in the command prompt:

Checking for updates... No updates found

Sum Calculator Version 1

The sum of 3 and 5 is 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

6. Conclude with the same strength as in the introduction

Answered: 1 week ago

Question

7. Prepare an effective outline

Answered: 1 week ago