Question: Here is the source code I have for the server-side: #include #include #include #include #include #include #include #include #define PORT 12008 #define MAX_PENDING_CONNECTIONS 5 #define

Here is the source code I have for the server-side:
#include
#include
#include
#include
#include
#include
#include
#include
#define PORT 12008
#define MAX_PENDING_CONNECTIONS 5
#define MAX_BUFFER_SIZE 1024
void handle_client(int client_socket, struct sockaddr_in client_address) {
char buffer[MAX_BUFFER_SIZE];
int bytes_received;
printf("New connection from %s:%d ", inet_ntoa(client_address.sin_addr), ntohs(client_address.sin_port));
while ((bytes_received = recv(client_socket, buffer, MAX_BUFFER_SIZE, 0)) > 0) {
buffer[bytes_received] = '\0';
printf("Received from client: %s ", buffer);
if (send(client_socket, buffer, strlen(buffer), 0) == -1) {
perror("send");
break;
}
}
close(client_socket);
printf("Connection closed from %s:%d ", inet_ntoa(client_address.sin_addr), ntohs(client_address.sin_port));
}
int main() {
int server_socket, client_socket;
struct sockaddr_in server_address, client_address;
socklen_t client_address_length = sizeof(client_address);
if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}
memset(&server_address, 0, sizeof(server_address));
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = INADDR_ANY;
server_address.sin_port = htons(PORT);
if (bind(server_socket, (struct sockaddr *)&server_address, sizeof(server_address)) == -1) {
perror("bind");
exit(1);
}
if (listen(server_socket, MAX_PENDING_CONNECTIONS) == -1) {
perror("listen");
exit(1);
}
printf("Server listening on port %d ", PORT);
while (1) {
if ((client_socket = accept(server_socket, (struct sockaddr *)&client_address, &client_address_length)) == -1) {
perror("accept");
continue;
}
pid_t pid = fork();
if (pid == -1) {
perror("fork");
continue;
} else if (pid == 0) {
// Child process
close(server_socket);
handle_client(client_socket, client_address);
exit(0);
} else {
// Parent process
close(client_socket);
}
}
close(server_socket);
return 0;
}
What would be the ideal client-side code for this? It needs to follow the given guidelines. Thank you guys so much for your help!
This problem involves implementing a remote shell tool using the standard model for network application, Client-Server model. You will write a server process that will be started on a Linux computer system. The server process will initialize itself and go to sleep waiting for a client process to conduct it, requesting for running and giving the output for a command. The client process is started, either on the same machine or on soem other system that is connected to the server's system with a network. You will use 4.3 BSD Sockets and the TCP/IP protocol to communicate between client and server. Server program: The server program must be executed in the background. It goes to sleep until a client wants to connect on that specific address. When the server process has finished providing its service to the client process, it goes back to sleep waiting for the next client request to arrive. Example command: ./server\& This is an example command for execution of the server program on any Linux machines, in background mode (\&). Client program: A unique PORT number will be used on which you will run your program. (The port number I need to use is 12008). For the client, you can telnet to the machine running your server process using its IP address and the port number. Example: 131.230.133.147:12008 You can also write a separate client program. For the client program, name of the host machine running the server program must be passed to the client on the command line. The server needs to run on a linux machine and the client can be conected from either a Linux or Windows machine. Also the server should acept multiple client connections simulataneously. Here's the server and client side code I have so far, let me know if there's a better version than this. (It needs to be in C). I would appreciate it if you also outlined steps for the Linux commands part, but I'm mainly asking for the server side and client side programs I would need. I appreciate all help I receive, thank you
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
