Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Description: You are required to implement a multi - threaded client / server application that counts number of specific characters given by a user using
Description:
You are required to implement a multithreaded clientserver application that counts number of
specific characters given by a user using TCP sockets. The server will accept TCP requests on a port
which is passed as an argument in the command line when starting the server. To pass the port, you
need to use service name rather than port number see below
ClientSide:
The client should be multithreaded. The main thread asks the user to enter two strings. The
second one In addition, it creates some other threads depending on the size of the second string which
are responsible to send TCP requests to the server. Each thread takes only one character from the
second string, append it to the end of the first string, and ask the corresponding thread of the server to
count the occurrence of that specific character in the given string. In other words, counting operation is
supposed to be performed by a number of threads equal the number of characters in the second string.
Every output operation on the standard output should be associated with the threadID doing that. In
addition to printing the count of each specific character, the main thread will output also the total
number of counted characters found in the first string as the sum of all returned values of the search
threads.
To run the client, you need to specify the server name and the service name in your code rather that
IP address and port number. To do so you need to edit the etchosts file in your client machine
and add a line that specifies the server name as nescountserver and assign it the IP address of
your server machine. Also, you need to edit the etcservices in your client machine and add a
line that specifies the port name as countport and assign it some value same port used when running
server, see below Your code should use the appropriate functions to convert between hostnamesIP
addresses and serviceport See the man page of the files for more information
ServerSide:
The server application is required to be multithreaded. The server waits for requests from the
client. For each request, a thread is created to server that request. In addition, the server main thread is
required to output the number of created threads so far.
A server thread searches the received string and return the count of the last character. It sends the
result back to the corresponding client thread and exits. Also, each thread report its finding on the
standard output together with its threadID
To run the server, you need to specify the service name rather than the port number on the
command line. To so you need to edit the etcservices in your server machine and add a line
that specifies the port name as countport and assign any value greater than if you are working
locally. To avoid conflict if working on the course server, each student is required to use a port number
for the server using the following format: abc for its connection, where abc is the least significant
digits of your students ID For example, a student whose ID is will have the server listening port
Example: where Ti is the thread number
client$
T:Enter an AlphaNumeric string to look in: hfgrtAffjhdADBFADRE
T:Enter characters to be counted as one string: rA
T: Creating threads to count for rA
T: # of rs in the first string
T: # of As in the first string
T: # of s in the first string
T: # of total occurrences
note: the output order and thread numbers might differ on your machine for client and server
Server$
T: waiting for client request
T: creating thread report the thread ID
T: number of created threads so far changes with every creation
T: received string: hfgrtAffjhdADBFADREr
T: # of rs
T: sent result back, exited.
T: waiting for client request
T: creating thread report the thread ID
T: number of created threads so far changes with every creation
T: received string: hfgrtAffjhdADBFADRE
T: # of s
T: sent result back, exited.
and so on for all reaming threads
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started