Question
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 needs to cache the version number of the data file. The server should only read the version number from the data file once and store it in a variable in memory. The server should NOT read the version number from the data file everytime a request is made for the version number.
2. Server "Hot Swap" Requirement---- The server does not need to be shut down and restarted. 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. 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 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
#include
using namespace std;
const char FILENAME[] = "data.bin"; const char IPADDR[] = "127.0.0.1"; const int PORT = 50000; const int QUERY = 1; const int UPDATE = 2;
int main() { // Add your code here for the server
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started