subject

In this assignment, you are provided with almost-working code that establishes a TCP socket connection over the INET domain (though for this assignment you should run and test your client-server code on the same machine). What is missing are the actual parameters for each of the four connection establishment socket APIs on the server and the two connection establishment socket APIs on the client (you will see a ? where the function parameters should be). Here are some identifying characteristics about the sockets you will be creating: • Use the INET domain for the socket type. • Use TCP sockets. • Use a backlog of 10 partially completed connections for the kernel to queue. Your goal for the first part of this assignment is to fill in the socket APIs with their needed parameters, but you should not add any new lines of code (until told to do so) as all of the needed supporting information such as variable declarations and initializations has already been provided. Use what is given to you, but do not change the intent of the program. If completed successfully, you will see the message "Server Message: SUCCESS" on the client side, but nothing on the server-side (although the server-side should still be running). The client-side only runs once while the server-side runs indefinitely, so you can run the client multiple times. To quit the server-side program, you may use CTRL-C (i. e., ^C). Go ahead and stop the server-side socket program now and then attempt to run the server-side socket program again. Does it work? Or does it give you an error? Knowing why you are getting this error is important! Normally, we would call unlink() to delete the socket "file", but this only works on UNIX domain sockets, not the INET sockets that we are using. For INET sockets, there is no file system token representing them, so we need to set a socket option to re-use the address as follows: int on = 1; setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); Now, enter the above two lines of code just before where the error is occurring. Then recompile and run your socket program again. Hopefully, you will no longer get these same errors as before. Make sure your client-server socket program works as expected and then submit both code files. 2 REQUIREMENTS: • No comments are required for this recitation assignment, except for your name at the top of the program. • Your program should have two components named "rec08svr. c" and "rec08cli. c", without the quotes, for the server and client code, respectively. • Your program will be graded based largely on whether it works correctly on the CSE machines (e. g., cse01, cse02, …, cse06), so you should make sure that your program compiles and runs on a CSE machine. • Although this assignment is to be submitted individually (i. e., each student will submit his/her own source code),

rec09svr. c

// compile: gcc rec09svr. c -o rec09svr

// usage : ./rec09svr port

#include

#include

#include

#include

#include

#include

#include

#include

#include

int main(int argc, char *argv[])

{

int listenfd = 0, connfd = 0, cli_size, portno;

struct sockaddr_in serv_addr, cli_addr;

char sendBuff[1025];

if ((listenfd = socket( ? )) == -1)

{

printf("socket error\n");

exit(EXIT_FAILURE);

}

memset(&serv_addr, '0', sizeof(serv_addr));

memset(sendBuff, '0', sizeof(sendBuff));

serv_addr. sin_family = AF_INET;

serv_addr. sin_addr. s_addr = htonl(INADDR_ANY);

portno = atoi(argv[1]);

serv_addr. sin_port = htons(portno);

if (bind( ? ) == -1)

{

printf("bind error\n");

exit(EXIT_FAILURE);

}

if (listen( ? ) == -1)

{

printf("listen error\n");

exit(EXIT_FAILURE);

}

while (1)

{

cli_size = sizeof(cli_addr);

if ((connfd = accept( ? )) == -1)

{

printf("accept error\n");

exit(EXIT_FAILURE);

}

strcpy(sendBuff, "Server Message: SUCCESS\n");

write(connfd, sendBuff, strlen(sendBuff));

close(connfd);

sleep(1);

}

return 0;

}

the second one

rec09cli. c

// compile: gcc rec09cli. c -o rec09cli

// usage : ./rec09cli port

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

int main(int argc, char *argv[])

{

int sockfd = 0, n = 0, portno;

char recvBuff[1025];

struct sockaddr_in serv_addr;

memset(recvBuff, '0', sizeof(recvBuff));

if ((sockfd = socket( ? )) < 0)

{

printf("socket error\n");

exit(EXIT_FAILURE);

}

serv_addr. sin_family = AF_INET;

portno = atoi(argv[1]);

serv_addr. sin_port = htons(portno);

serv_addr. sin_addr. s_addr = inet_addr("127.0.0.1");

if (connect( ? ) < 0)

{

printf("connect error\n");

exit(EXIT_FAILURE);

}

while ((n = read(sockfd, recvBuff, sizeof(recvBuff)-1)) > 0)

{

recvBuff[n] = 0;

if (fputs(recvBuff, stdout) == EOF)

{

printf("fputs error\n");

}

}

if (n < 0)

{

printf("read error\n");

}

return 0;

}

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 20:00, bowmanari2154
What is used to analyze and summarize your data without graphical support
Answers: 1
image
Computers and Technology, 23.06.2019 01:00, Ltik11900
Write the command that can be used to answer the following questions. (hint: try each out on the system to check your results.) a. find all files on the system that have the word test" as part of their filename. b. search the path variable for the pathname to the awk command. c. find all files in the /usr directory and subdirectories that are larger than 50 kilobytes in size. d. find all files in the /usr directory and subdirectories that are less than 70 kilobytes in size. e. find all files in the / directory and subdirectories that are symbolic links. f. find all files in the /var directory and subdirectories that were accessed less than 60 minutes ago. g. find all files in the /var directory and subdirectories that were accessed less than six days ago. h. find all files in the /home directory and subdirectories that are empty. i. find all files in the /etc directory and subdirectories that are owned by the group bin."
Answers: 1
image
Computers and Technology, 23.06.2019 01:50, akornegay2
Write a program that uses a random number generator to generate a two digit positive integer and allows the user to perform one or more of the following operations: a. double the number. b. reverse the digits of the number. c. raise the number to the power of 2, 3, or 4. d. sum the digits of the number. e. if the number is a two-digit number, then raise the first digit to the power of the second digit. f. if the number is a three-digit number and the last digit is less than or equal to 4, then raise the first two digits to the power of the last digit. after performing an operation if the number is less than 10, add 10 to the number. also, after each operation determine if the number is prime. each successive operation should be performed on the number generated by the last operation. your program should not contain any global variables and each of these operations must be implemented by a separate function. also, your program should be menu driven. 7. (fraction calculator) write a program that
Answers: 1
image
Computers and Technology, 23.06.2019 17:00, Need1ng
The more powerful, 60 volt cables and the main power shut-off on an hev are both colored orange.
Answers: 1
You know the right answer?
In this assignment, you are provided with almost-working code that establishes a TCP socket connecti...

Questions in other subjects: