Question

Assignment One program will be the update server and the other will be the update client....

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

IF YOUU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU

ANSWER:

CODE:

#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <string.h>

#define PORT 50000
#define LISTENQ 3
#define MAXLINE 2

//str_update function
void str_update(int sockfd)
{
   ssize_t n;
   char buffer[MAXLINE];
   n=read(sockfd,buffer,MAXLINE);
   if(n>0)
   {
       printf("read from client:%s\n",buffer);          
   }
   else
   {
       fprintf(stderr,"Unable to read from client!");
   }
}

//update server
//main function for update server
int main(int argc, char **argv)
{
   char[10] data_file_path = "./data.bin"; //name and path of data file
   FILE *data_file; //handle for data file
   char[2] version_number; //version number to be read from file
   int listenfd, connfd; //file descriptors
   pid_t childpid;//id for child process
   //soclen_t clilen;
   unsigned int clilen;
  
   struct sockaddr_in servaddr,cliaddr; //server address and client address
  
   //open data file
   data_file = fopen(data_file_path,'r');
   if(!data_file)
   {
       fprintf(stderr,"ERROR:Could not open data file:"));
       return EXIT_FAILURE;
   }
   else //read version number from file
   {
       fgets(version_number,sizeof(version_number),data_file);
       printf("Version number:%s\n",version_number);
   }
  
   //create socket
   listenfd = socket(AF_INET,SOCK_STREAM,0);
   bzero(&servaddr,sizeof(servaddr)); //initialize server address with zero
   //initialize server address
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
   servaddr.sin_port = htons(PORT);
   //bind the socket with speicified port
   bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
   //listen to the socket
   listen(listenfd,LISTENQ);
   //receive and handle client request
   for(;;)
   {
       clilen = sizeof(cliaddr);
       connfd = accept(listenfd,(struct sockaddr *)&cliaddr,&clilen); //accept connection from client
       //child process
       if( (childpid = fork())= 0)
       {
           close(listenfd); //close socket
           str_update(connfd); //process client request
           exit(0);
       }
       close(connfd); //close connection to client
   }
}

RATE THUUMBSUP PLEASE

THANKS

Add a comment
Know the answer?
Add Answer to:
Assignment One program will be the update server and the other will be the update client....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write two programs Client and Server

    Given two integer matrices A and B, you are requested to compose a program to perform matrix addition (A + B). Both matrices have N rows and M columns; N > 1, M > 1; You need to divide both (A and B) into four equal (or close to equal) size of submatrices (A0,0, A0,1, A1,0, A1,1 and B0,0, B0,1, B1.0, B1.1)andeachsubmatrixhasdimensioncloseto(N/2)x(M/2). YouneedtocreatefourJavathreads each thread performs a subset of addition on one pair of the submatrices. Example, thread 0 performs addition...

  • Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will...

    Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will write a client and server program that enables the client to determine the round-trip time (RTT) to the server. To determine the RTT delay, the client records the time on sending a ping request to the server, and then records the time on receiving a ping response from the server. The difference in the two times is the RTT. The ping message contains 2...

  • *****Can someone please HELP me with this assignment please, I am struggling with this assignment and...

    *****Can someone please HELP me with this assignment please, I am struggling with this assignment and would appreciate some help, needs to be done in c/c++ ******* (100 marks) In this problem, you will write a file transfer program for transferring files between two computers connected by a network. The protocol that you will implement is called the Simple File Transfer Protocol (SFTP). The complete description for SFTP is given below. PART 1 SFTP is a simple protocol for transferring...

  • To develop a client/server application using TCP sockets and the C programming language that is capable...

    To develop a client/server application using TCP sockets and the C programming language that is capable of supporting multiple concurrent service requests from different clients. PROBLEM You are to use the Ubuntu operating system as well as both the client and the server programs. You are to modify your server program to process requests from more than one client concurrently. This means different clients may request either the same service or a total different one. The services supported by your...

  • In Python, make changes in the client code, so that the client allows the user to...

    In Python, make changes in the client code, so that the client allows the user to continue to send multiple requests until the user types in “Quit”. This means that the client process should not exit after the user sends one request and receives one response. Instead, the client process should be able to receive subsequent inputs from the user. You need to have a loop in the client code, so that it can accept the user request until the...

  • Write two C programs that run a server program and a client program concurrently. Server program:...

    Write two C programs that run a server program and a client program concurrently. Server program: The server program provides a simple search for a specific value in an array sent to it from a client. If the value appears in the array, the server indicates the index of the first occurrence of that value in the array. The server sends the client search value and its array position. If the value does not occur in the array, only the...

  • Objective: Create programs that are run independently and can use simple IPC using FIFOs/named pipes to...

    Objective: Create programs that are run independently and can use simple IPC using FIFOs/named pipes to pass information back and forth in a client/server fashion. The information/request from the client will look like simple semaphore system calls and will include information for the server to be able to identify which client requested it and what request it is and its associated parameters. This assignment requires the analysis, implementation, testing and documentation of two C program that use C on the...

  • Use Python TCP socket to implement an application with client-server architecture. In this application, client must...

    Use Python TCP socket to implement an application with client-server architecture. In this application, client must read a line of characters from its input and send it to the server. The server must remove all non-alphanumeric characters from the input and send the modified data to the client. The client must receive the modified data and displays it on its screen.

  • Using network sockets, write a C program called client that receives three command-line arguments in the...

    Using network sockets, write a C program called client that receives three command-line arguments in the form: client host port file and sends a request to a web server. The command-line arguments are hostRepresents the web server to connect to port Represents the port number where a request is sent. Normally an HTTP request is sent over port 80, but this format allows for custom ports file Represents the file requested from the web server Your program should create a...

  • Here is the description of the client and server programs that you need to develop in C using TCP: Suppose we have a simple student query system, where the server keeps student's info in an array...

    Here is the description of the client and server programs that you need to develop in C using TCP: Suppose we have a simple student query system, where the server keeps student's info in an array of struct student_info ( char abc123171 char name [101 double GPA; To simplify the tasks, the server should create a static array of 10 students with random abc123, name, and GPA in the server program. Then the server waits for clients. When a client...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT