Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I edit this server code so that before it writes to the client it prints: Sending to During the file transfer at every

How do I edit this server code so that before it writes to the client it prints:

Sending to

During the file transfer at every 10% progress:

Sent 10% of

Sent 20% of

Sent 30% of

When the transfer is complete:

Finished sending to

/* This is the server code */ #include "file-server.h" #include

#define QUEUE_SIZE 10

int main(int argc, char *argv[]) { int s, b, l, fd, sa, bytes, on = 1; char str[]= "hello"; char buf[BUF_SIZE]; /* buffer for outgoing file */ struct sockaddr_in channel; /* holds IP address */

/* Build address structure to bind to socket. */ memset(&channel, 0, sizeof(channel)); /* zero channel */ channel.sin_family = AF_INET; channel.sin_addr.s_addr = htonl(INADDR_ANY); channel.sin_port = htons(SERVER_PORT);

/* Passive open. Wait for connection. */ s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); /* create socket */ if (s < 0) fatal("socket failed"); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on));

b = bind(s, (struct sockaddr *) &channel, sizeof(channel)); if (b < 0) fatal("bind failed");

l = listen(s, QUEUE_SIZE); /* specify queue size */ if (l < 0) fatal("listen failed");

/* Socket is now set up and bound. Wait for connection and process it. */ while (1) { sa = accept(s, 0, 0); /* block for connection request */ if (sa < 0) fatal("accept failed");

read(sa, buf, BUF_SIZE); /* read file name from socket */

/* Get and return the file. */ fd = open(buf, O_RDONLY); /* open the file to be sent back */ if (fd < 0) fatal("open failed"); printf("%s", str);

while (1) { bytes = read(fd, buf, BUF_SIZE); /* read from file */ if (bytes <= 0) break; /* check for end of file */ write(sa, buf, bytes); /* write bytes to socket */ } close(fd); /* close file */ close(sa); /* close connection */ } }

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

Recommended Textbook for

Students also viewed these Databases questions

Question

1. Let a, b R, a Answered: 1 week ago

Answered: 1 week ago

Question

1. Define the nature of interviews

Answered: 1 week ago

Question

2. Outline the different types of interviews

Answered: 1 week ago