Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Find the solution using C language PROBLEM 1Find the solutions for the following

ID: 3748274 • Letter: F

Question

Find the solution using C language

PROBLEM 1Find the solutions for the following and please use C for your code A. MULTI-FUNCTION CLIENT AND SERVER: This problem involves the development of a simple client-server application. Upon execution, the client should print a menu of possible commands, and prompt the user to enter the number of a command which should be executed on the server. Then, the client should send the number to the server (which is waiting to read requests on a predefined UDP port). The server should read the number from the client and execute the appropriate command, returning the results (as a string) to the client. The client should print the reply to the console and then be ready to accept additional commands from the user The command that should be available are; 1. Current time 2. PID (process ID) of the server 3. Random number between 1 and 20, inclusive Note: The Application Layer Protocol should be clearly defined, and must exchange data in ASCII format only. The server should be connectionless and iterative, i.e. only process one request at a time (see net2/sever.c). Don't worry about making the communication reliable, e.g by adding timeouts, etc. B. INTERRUPT HANDLER: In Part A, we didn't provide a way for the client or server to exit you have to interrupt them using C. Modify the client from Part A to implement an interrupt handler (using signalO) to "catch" the C key-press (SIGINT). Once the client detects it should send a command to the server numbered 0, which will cause the server to shut down. Modify the server from Part A to do this. Note that a user should not be able to select "O" as a command on the client side: it is only sent in response to . Additionally, when the client receives a , it should prit "Goodbye!" to the standard output, and then exit. C. CONNECTION-ORIENTED CLIENT-SERVER APPLICATION: Repeat Part A using TCP instead of UDP; that is, implement an iterative, connection-oriented server, and corresponding client. Each request should cause a new connection to be established (see ne o net3/erver

Explanation / Answer

Server Code

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

int main(){
int sockett, new_socket;
char buff[1024];
struct sockaddr_in serverAddr;
struct sockaddr_storage serverStorage;
socklen_t addr_siz;
sockett = socket(PF_INET, SOCK_STREAM, 0);
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(7891);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
memset(serverAddr.sin_zero, '', sizeof serverAddr.sin_zero);
bind(sockett, (struct sockaddr *) &serverAddr, sizeof(serverAddr));
if(listen(sockett,5)==0)
    printf("Listening ");
else
    printf("Error ");
addr_siz = sizeof serverStorage;
new_socket = accept(sockett, (struct sockaddr *) &serverStorage, &addr_siz);
strcpy(buff,"Hello World ");
send(new_socket,buff,13,0);

return 0;
}


Client Code
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

int main(){
int client_socket;
char buff[1024];
struct sockaddr_in serverAddr;
socklen_t addr_siz;
client_socket = socket(PF_INET, SOCK_STREAM, 0);
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(7891);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
memset(serverAddr.sin_zero, '', sizeof serverAddr.sin_zero);
addr_siz = sizeof serverAddr;
connect(client_socket, (struct sockaddr *) &serverAddr, addr_siz);
recv(client_socket, buff, 1024, 0);
printf("Data received: %s",buff);  
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote