Question: newsockfd = accept(sockfd, (struct sockaddr *)&client_addr, &client_len); // Step 5: Read data from the connection memset(buffer, 0, sizeof(buffer)); int len = read(newsockfd, buffer, 100); printf(Received
newsockfd = accept(sockfd, (struct sockaddr *)&client_addr, &client_len); // Step 5: Read data from the connection memset(buffer, 0, sizeof(buffer)); int len = read(newsockfd, buffer, 100); printf("Received %d bytes: %s", len, buffer); // Step 6: Close the connection close(newsockfd); close(sockfd); return 0; } Does the program get blocked when invoking listen() until a connection comes? (2) What is the purpose of the accept()? (3) Whydoes the accept() call create a new socket? Why cannot we use the same one that is used in the listen() call?
#include #include #include #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

newsockfd = accept(sockfd, (struct sockaddr *)&client_addr, &client_len); // Step 5: Read data from the connection memset(buffer, 0, sizeof(buffer)); int len = read(newsockfd, buffer, 100); printf("Received %d bytes: %s", len, buffer); // Step 6: Close the connection close(newsockfd); close(sockfd); return 0; } Does the program get blocked when invoking listen() until a connection comes? (2) What is the purpose of the accept()? (3) Whydoes the accept() call create a new socket? Why cannot we use the same one that is used in the listen() call?