Please implement following The source file name and the destination file name must be given to the client program as arg

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please implement following The source file name and the destination file name must be given to the client program as arg

Post by answerhappygod »

Please implement following
The source file name and the destination file name must be given
to the client program as arguments.
The client program must transfer the destination file name to
the server program before the data transfer.
The FTA client and server programs should only use the SWAP and
SDP APIs.
The FTA client and server programs should print your name and
student number.
client side:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <arpa/inet.h>
#define MAXLINE 128 // maximum bytes to receive and send at
once
// External functions
extern int swap_open(unsigned int addr, unsigned short
port);
extern int swap_write(int sd, unsigned char buf[], int
length);
extern void swap_close(int sd);
int main(int argc, char *argv[])
{
unsigned short server_port;
unsigned int server_address;
unsigned char buf[MAXLINE];
int sd, n, in;
if (argc < 4) {
fprintf(stderr, "Usage: %s address
port input-filename\n", argv[0]);
exit(1);
}
// set values for server address and port
number
server_address = inet_addr(argv[1]);
// server address
server_port = htons(atoi(argv[2]));
// port number
// connect to the swap server
sd = swap_open(server_address, server_port);
if (sd < 0) {
fprintf(stderr, "swap_open
error\n");
exit(0);
}
//Students to code the following:
//open input file for reading
//send input file name o the server
// loop
//if there is data in the file, send
it to the server
// end-loop
// close the connection to the swap server
swap_close(sd);
//close connection to input file
close(in);
}
server side:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <arpa/inet.h>
#define MAXLINE 128 // maximum bytes to receive and send at
once
// External functions
extern int swap_wait(unsigned short port);
extern int swap_read(int sd, unsigned char buf[]);
extern void swap_close(int sd);
int main(int argc, char *argv[])
{
unsigned short server_port;
unsigned int server_address;
unsigned char message[MAXLINE];
int sd, n, out;
if (argc < 2) {
fprintf(stderr, "Usage: %s port\n",
argv[0]);
exit(1);
}
// set values for server address and port
number
server_port = htons(atoi(argv[1]));
// connect to the port allocated to the swap
server
sd = swap_wait(server_port);
if (sd < 0) {
fprintf(stderr, "swap_open
error\n");
exit(0);
}
//Students to code the following:
//read in the first message as the new name of the
file
//open output file for writing
//begin-loop
//get the file data from the client
until end-of-file
//end-loop
// close the connection to the swap servfer
swap_close(sd);
//close connection to output file
close(out);
}
Please do not paste from other post
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply