Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I would appreciate a solution for this. At the bottom is the concurrent-thread server and client programs, you may use as base code as stated

I would appreciate a solution for this. At the bottom is the concurrent-thread server and client programs, you may use as base code as stated in question.

image text in transcribedimage text in transcribed

concurrent-threader server program

#include  #include  #include  #include  #include  /* CONCURRENT SERVER: THREAD EXAMPLE Must be linked with the "pthread" library also, e.g.: cc -o example example.c -lnsl -lsocket -lpthread This program creates a connection socket, binds a name to it, then listens for connections to the sockect. When a connection is made, it accepts messages from the socket until eof, and then waits for another connection... This is an example of a CONCURRENT server -- by creating threads several clients can be served at the same time... This program has to be killed to terminate, or alternately it will abort in 120 seconds on an alarm... */ #define PORTNUMBER 10010 struct serverParm { int connectionDesc; }; void *serverThread(void *parmPtr) { #define PARMPTR ((struct serverParm *) parmPtr) int recievedMsgLen; char messageBuf[1025]; /* Server thread code to deal with message processing */ printf("DEBUG: connection made, connectionDesc=%d ", PARMPTR->connectionDesc); if (PARMPTR->connectionDesc connectionDesc,messageBuf,sizeof(messageBuf)-1)) > 0) { recievedMsgLen[messageBuf] = '\0'; printf("Message: %s ",messageBuf); if (write(PARMPTR->connectionDesc,"GOT IT\0",7) connectionDesc); /* Avoid descriptor leaks */ free(PARMPTR); /* And memory leaks */ return(0); /* Exit thread */ } main () { int listenDesc; struct sockaddr_in myAddr; struct serverParm *parmPtr; int connectionDesc; pthread_t threadID; /* For testing purposes, make sure process will terminate eventually */ alarm(120); /* Terminate in 120 seconds */ /* Create socket from which to read */ if ((listenDesc = socket(AF_INET, SOCK_STREAM, 0)) connectionDesc = connectionDesc; if (pthread_create(&threadID, NULL, serverThread, (void *)parmPtr) != 0) { perror("Thread create error"); close(connectionDesc); close(listenDesc); exit(1); } printf("Parent ready for another connection "); } } 

concurrent-thread client program

#include  #include  #include  #include  #include  #include  #include  #define MAXLINE 4096 /*max text line length*/ #define SERV_PORT 10010 /*port*/ int main(int argc, char **argv) { int sockfd; struct sockaddr_in servaddr; char sendline[MAXLINE], recvline[MAXLINE]; // alarm(300); // to terminate after 300 seconds //basic check of the arguments //additional checks can be inserted if (argc !=2) { perror("Usage: TCPClient  "); exit(1); } //Create a socket for the client //If sockfd 

Part1 Socket Programming, Client-Server Programming, Concurrent Server with Threads Remote command processing, a Mutex for synchronization Project Description A client will send a simple command via socket program to a server listening. The server will receive a command from the client, use a thread to handle this command to be processed, and then echo back its result of the command to the client. You need to set up a pipe for each thread to process the command to output its result through pipe, then to socket (back to the client) For example, try first with ls command. That is, ls command is sent from the client, the server-thread receives it and process the 1s command in the server, and then pipe its result to the socket so that the result is then sent back to the server. Note: Server should be able to handle one command (e.g., "ls") or two commands in pipe ("ls I sort"). There is no need to handle any file redirection in command. You may use or modify the sample socket programs in Week 13 Activity folder (e.g., concurrent-thread server and client programs) for your base code to be modified, and the sample shell program in Part2 for each thread to handle the incoming command or two commands in pipe Task #1 name it myServerl c) program to accept one argument which is the port number of the server to bind and listen to. Second (2), modify the client program (name it myclienti.c) to accept two arguments (IP address and port number of the Server) [Note: If you have a unique port of your favorite (for example, my favorite port 10300 from my UTD octidwhich is rkm010300) and for sure no one will ever use it, then you may use this port throughout this exercise. Or we may try to get a port number (without using someone's and to use a port# which is available between 10K and 64K) using current date and time Use petstat command to check whether a port is available or not (taken by someone including you) arning and Caution. Your servers listening port must be free (not taken by someone else) and pick one (onnon-port between 10K and 64K Ifit is taken, your server should use another port available, to be connected by your client. Do not use any port being used by someone else for server to bind and for client to connect to someone's server, not yours). Check whether the previous server is still running using ps.command. If so, kill it before you run the server again. When you are done, make sure to check whether there is your server still up and listening with "ps" command and to kill any of your servers. Part1 Socket Programming, Client-Server Programming, Concurrent Server with Threads Remote command processing, a Mutex for synchronization Project Description A client will send a simple command via socket program to a server listening. The server will receive a command from the client, use a thread to handle this command to be processed, and then echo back its result of the command to the client. You need to set up a pipe for each thread to process the command to output its result through pipe, then to socket (back to the client) For example, try first with ls command. That is, ls command is sent from the client, the server-thread receives it and process the 1s command in the server, and then pipe its result to the socket so that the result is then sent back to the server. Note: Server should be able to handle one command (e.g., "ls") or two commands in pipe ("ls I sort"). There is no need to handle any file redirection in command. You may use or modify the sample socket programs in Week 13 Activity folder (e.g., concurrent-thread server and client programs) for your base code to be modified, and the sample shell program in Part2 for each thread to handle the incoming command or two commands in pipe Task #1 name it myServerl c) program to accept one argument which is the port number of the server to bind and listen to. Second (2), modify the client program (name it myclienti.c) to accept two arguments (IP address and port number of the Server) [Note: If you have a unique port of your favorite (for example, my favorite port 10300 from my UTD octidwhich is rkm010300) and for sure no one will ever use it, then you may use this port throughout this exercise. Or we may try to get a port number (without using someone's and to use a port# which is available between 10K and 64K) using current date and time Use petstat command to check whether a port is available or not (taken by someone including you) arning and Caution. Your servers listening port must be free (not taken by someone else) and pick one (onnon-port between 10K and 64K Ifit is taken, your server should use another port available, to be connected by your client. Do not use any port being used by someone else for server to bind and for client to connect to someone's server, not yours). Check whether the previous server is still running using ps.command. If so, kill it before you run the server again. When you are done, make sure to check whether there is your server still up and listening with "ps" command and to kill any of your servers

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago