Question
i just need the changing in following attached code kindly who are going to do this please do not just change the variables only but
i just need the changing in following attached code kindly who are going to do this please do not just change the variables only but also change the things that are required to make this code unique and plagiarised free and the language will be the same C programming language.
this is the question.
In this assignment you are required to follow the Unix domain server and client example done in the classroom. After this point, you need to setup the server in a way that it will process the data sent by the client and send back the processed data. You must read at least two set of data, and send back at least a piece of information. For instance, client might send two numbers and the server will send the summation back. This is only an example, please do something a little more complicated. I do not want to see same operation over and over again in the assignments. You can use scanf and printf with dup2 to obtain numbers. Alternatively, you could read the text and use sscanf and sprintf. You could also perform text based operations. It is up to you.
You must perform all error checks.
CODE ;
TCP SERVER;
#include #include #include #include #include #include #include #define MAX 80 #define PORT 8080 #define SA struct sockaddr
// Function designed for chat between client and server. void func(int connfd) { char buff[MAX]; int n; // infinite loop for chat for (;;) { bzero(buff, MAX);
// read the message from client and copy it in buffer read(connfd, buff, sizeof(buff)); // print buffer which contains the client contents printf("From client: %s\t To client : ", buff); bzero(buff, MAX); n = 0; // copy server message in the buffer while ((buff[n++] = getchar()) != ' ') ;
// and send that buffer to client write(connfd, buff, sizeof(buff));
// if msg contains "Exit" then server exit and chat ended. if (strncmp("exit", buff, 4) == 0) { printf("Server Exit... "); break; } } }
// Driver function int main() { int sockfd, connfd, len; struct sockaddr_in servaddr, cli;
// socket create and verification sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd == -1) { printf("socket creation failed... "); exit(0); } else printf("Socket successfully created.. "); bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(PORT);
// Binding newly created socket to given IP and verification if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0) { printf("socket bind failed... "); exit(0); } else printf("Socket successfully binded.. ");
// Now server is ready to listen and verification if ((listen(sockfd, 5)) != 0) { printf("Listen failed... "); exit(0); } else printf("Server listening.. "); len = sizeof(cli);
// Accept the data packet from client and verification connfd = accept(sockfd, (SA*)&cli, &len); if (connfd < 0) { printf("server accept failed... "); exit(0); } else printf("server accept the client... ");
// Function for chatting between client and server func(connfd);
// After chatting close the socket close(sockfd); }
TCP CLIENT :
#include #include #include #include #include #define MAX 80 #define PORT 8080 #define SA struct sockaddr void func(int sockfd) { char buff[MAX]; int n; for (;;) { bzero(buff, sizeof(buff)); printf("Enter the string : "); n = 0; while ((buff[n++] = getchar()) != ' ') ; write(sockfd, buff, sizeof(buff)); bzero(buff, sizeof(buff)); read(sockfd, buff, sizeof(buff)); printf("From Server : %s", buff); if ((strncmp(buff, "exit", 4)) == 0) { printf("Client Exit... "); break; } } }
int main() { int sockfd, connfd; struct sockaddr_in servaddr, cli;
// socket create and varification sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd == -1) { printf("socket creation failed... "); exit(0); } else printf("Socket successfully created.. "); bzero(&servaddr, sizeof(servaddr));
// assign IP, PORT servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); servaddr.sin_port = htons(PORT);
// connect the client socket to server socket if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) != 0) { printf("connection with the server failed... "); exit(0); } else printf("connected to the server.. ");
// function for chat func(sockfd);
// close the socket close(sockfd); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started