The following program sets up a single client/server connection. When the client connects, the server reads any incoming data as text and prints it out one line at a time. If the server receives the string “shutdown”, then it closes the socket and exits. Download this program Download this program into GCC and run the code. Then update your code to allow for the server to manage concurrent connections on the same port. Use IP address 127.0.0.1. Page of 3 ZOOM /* Server code */ #define BUF_SIZE 1024 #define LISTEN_PORT 8080 int main(int argc, char *argv[]) { int sock_listen, sock_recv; int i, addr_size, bytes_received; int incoming_len; int recv_msg_size; struct sockaddr_in my_addr, recv_addr; int select_ret; fd_set readfds; struct timeval timeout={0,0}; struct sockaddr remote_addr; char buf[BUF_SIZE]; /* create socket for listening */ sock_listen = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock_listen < 0) { printf("socket() failed\n"); exit(0); } /* make local address structure */ memset(&my_addr, 0 sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_addr.s_addr = htonl(INADDR_ANY); my_addr.sin_port = htons((unsigned short)LISTEN_PORT); /* bind socket to the local address */ i = bind(sock_listen, (struct sockaddr *) &my_addr, sizeof(my_addr)); if (i < 0) { printf("bind() failed\n"); exit(0); } /* listen */ i = listen(sock_listen, 5); if (i < 0) { printf("listen() failed\n"); exit(0); } /* get new socket to receive data on */ addr_size = sizeof(recv_addr); sock_recv = accept(sock_listen, (struct sockaddr *) &recv_addr, &addr_size); while (1) { bytes_received = recv(sock_recv, buf, BUF_SIZE, 0); buf[bytes_received] = 0; printf("Received: %s\n", buf); if (strcmp(buf, "shutdown") == 0) break; } close(sock_recv); close(sock_listen); } /* Client code */ #define BUF_SIZE 1024 #define SERVER_IP "192.168.0.1" #define SERVER_PORT 8080 int main(int argc, char *argv[]) { int sock_send; int i; int send_len, bytes_sent; char text[80], buf[BUF_SIZE]; struct sockaddr_in addr_send; /* create socket for sending data */ sock_send = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock_send < 0) { printf("socket() failed\n"); exit(0); } /* create socket address structure to connect to */ memset(&addr_send, 0, sizeof(addr_send)); addr_send.sin_family = AF_INET; addr_send.sin_addr.s_addr = inet_addr(SERVER_IP); addr_send.sin_port = htons((unsigned short) SERVER_PORT); /* connect to server */ i = connect(sock_send, (struct sockaddr *) &addr_send, sizeof(addr_send)); if (i < 0) { printf("connect() failed\n"); exit(0); } while (1) { /* send some data */ printf("Send? "); scanf("%s", text); if (strcmp(text, "quit") == 0) break; strcpy(buf, text); send_len = strlen(text); bytes_sent = send(sock_send, buf, send_len, 0); } close(sock_send); } Please provide the complete code for server as well as client side

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The following program sets up a single client/server connection. When the client connects, the server reads any incoming data as text and prints it out one line at a time. If the server receives the string “shutdown”, then it closes the socket and exits. Download this program Download this program into GCC and run the code. Then update your code to allow for the server to manage concurrent connections on the same port. Use IP address 127.0.0.1. Page of 3 ZOOM /* Server code */ #define BUF_SIZE 1024 #define LISTEN_PORT 8080 int main(int argc, char *argv[]) { int sock_listen, sock_recv; int i, addr_size, bytes_received; int incoming_len; int recv_msg_size; struct sockaddr_in my_addr, recv_addr; int select_ret; fd_set readfds; struct timeval timeout={0,0}; struct sockaddr remote_addr; char buf[BUF_SIZE]; /* create socket for listening */ sock_listen = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock_listen < 0) { printf("socket() failed\n"); exit(0); } /* make local address structure */ memset(&my_addr, 0 sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_addr.s_addr = htonl(INADDR_ANY); my_addr.sin_port = htons((unsigned short)LISTEN_PORT); /* bind socket to the local address */ i = bind(sock_listen, (struct sockaddr *) &my_addr, sizeof(my_addr)); if (i < 0) { printf("bind() failed\n"); exit(0); } /* listen */ i = listen(sock_listen, 5); if (i < 0) { printf("listen() failed\n"); exit(0); } /* get new socket to receive data on */ addr_size = sizeof(recv_addr); sock_recv = accept(sock_listen, (struct sockaddr *) &recv_addr, &addr_size); while (1) { bytes_received = recv(sock_recv, buf, BUF_SIZE, 0); buf[bytes_received] = 0; printf("Received: %s\n", buf); if (strcmp(buf, "shutdown") == 0) break; } close(sock_recv); close(sock_listen); } /* Client code */ #define BUF_SIZE 1024 #define SERVER_IP "192.168.0.1" #define SERVER_PORT 8080 int main(int argc, char *argv[]) { int sock_send; int i; int send_len, bytes_sent; char text[80], buf[BUF_SIZE]; struct sockaddr_in addr_send; /* create socket for sending data */ sock_send = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock_send < 0) { printf("socket() failed\n"); exit(0); } /* create socket address structure to connect to */ memset(&addr_send, 0, sizeof(addr_send)); addr_send.sin_family = AF_INET; addr_send.sin_addr.s_addr = inet_addr(SERVER_IP); addr_send.sin_port = htons((unsigned short) SERVER_PORT); /* connect to server */ i = connect(sock_send, (struct sockaddr *) &addr_send, sizeof(addr_send)); if (i < 0) { printf("connect() failed\n"); exit(0); } while (1) { /* send some data */ printf("Send? "); scanf("%s", text); if (strcmp(text, "quit") == 0) break; strcpy(buf, text); send_len = strlen(text); bytes_sent = send(sock_send, buf, send_len, 0); } close(sock_send); } Please provide the complete code for server as well as client side in C

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education