Question: PLEASE HELP ME IN UNDERSTANDING THE CODE BASICALLY WHAT IS HAPPENING IN THE CODE ABOUT VARIABLES LIBRARIES DEFINE FUNCTIONS AND EVERYTHING IN THE CODE STEP

PLEASE HELP ME IN UNDERSTANDING THE CODE BASICALLY WHAT IS HAPPENING IN THE CODE ABOUT VARIABLES LIBRARIES DEFINE FUNCTIONS AND EVERYTHING IN THE CODE STEP BY STEP

#include #include #include #include #include #include #include #include #include #define MAX 80 #define PORT 5500 #define SA struct sockaddr

void func(int connfd) { char buff[MAX]; int n; for (;;) { bzero(buff, MAX); read(connfd, buff, sizeof(buff)); printf("From client: %s\t To client : ", buff); bzero(buff, MAX); n = 0; while ((buff[n++] = getchar()) != ' ') ; write(connfd, buff, sizeof(buff)); if (strncmp("exit", buff, 4) == 0) { printf("Server Exit... "); break; } } } 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)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(PORT); if ((bind(sockfd, (SA*)&servaddr, sizeof(servaddr))) != 0) { printf("socket bind failed... "); exit(0); } else printf("Socket successfully binded.. "); if ((listen(sockfd, 5)) != 0) { printf("Listen failed... "); exit(0); } else printf("Server listening.. "); len = sizeof(cli); connfd = accept(sockfd, (SA*)&cli, &len); if (connfd < 0) { printf("server accept failed... "); exit(0); } else printf("server accept the client... "); func(connfd); close(sockfd); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!