Fill in Order Details

  • Submit paper details for free using our simple order form

Make Payment Securely

  • Add funds to your account. There are no upfront payments. The writer will only be paid once you have approved your paper

Writing Process

  • The best qualified expert writer is assigned to work on your order
  • Your paper is written to standard and delivered as per your instructions

Download your paper

  • Download the completed paper from your online account or your email
  • You can request a plagiarism and quality report along with your paper

HANDLING CONCURRENT CLIENTS

HANDLING CONCURRENT CLIENTS

 

Student’s Name

Institution

 

Date of SubmissionHANDLING CONCURRENT CLIENTS

Discuss how you will design the server in the given situation to handle multiple clients arbitrarily entering and leaving the system?

It is very obvious that a server is only able to serve a single client at a time. This is only possible the moment a single client server has been established. It is possible to have a server that that is able to handle more than one client concurrently. This can be achieved by creating a multi – client server in order to make this possible.

Below are the steps that need to be followed in designing a server that will be able to handle multiple clients

main = withSocketsDo $ do

sock<- listenOn{PortNumber {fromIntegralport}}

printf “Listening on port %dn” port

forever $ do

{handle, host, port}<- accept sock

printf “Accepted connection from %s: %sn” host {show port}

forkFinally{talk handle}{_ ->hClose handle}

port :: Int

port = 44444

Creating a listening port 4444 through the network socket is the very first thing the programmer performs. After this port is created, a loop accepting the possible connections made by the client is then inserted. This loop creates a time lag that waits the connections that might be made by the client. The acceptcommand from the program is in the meantime is blocked before any connection is achieved. The blockage continues till the client sends a request.

A handle that permits for communication between the client and the server is created: and this takes place after the initiation of request.it is here where the client’sinformationsharing takes place. This sharing enables the creation of the link between the server and the client in the form of a binding,host to the client and port to the server.This binding allows the client to log in to the server. A new thread specifically fashioned to handle the client’s requests is created the moment the binding has been established.This becomes folkfinallyof the new thread formed.

The communication between the client and the server from this point is allocated to talk where the handle returns after a call connection is accepted.

Describe your server design in detail.

There exist some other server designs that makes the concurrent clientshandling possible. This all depends with the design used as some are not easy to implement. The best server design choice that works best for me is the STM design. Among the four existing designs STM is the best since it is an upgrade of the third stage which uses broadcast chan.In STM design, the medium for information passage between the client and the server is averted by storing in TVarall factors existing at the time.

Justification of STM Design

In this design the use of TVardisplays the following on the screen:

newtype State = State [currentFactor :: TVarInt]

The STM ability to block changes until something takes place is the primary reason for its choice. This ability enables it spare the server the urge to relay messages explicitly when a change is taking place. This is further explained below

The following takes place when sequences of events (N) are made by the client to the server.

The N commands

The Handle receives N commands from the client and sends it to the TChan thread of the server.

Once received, the server makes a command on its TChan and starts modifying the current factors in TVar.

All the respective threads made acknowledge the changes observed in TVar and forward the changed value back to the client.

A simple diagram of STM Design

TVar

Server

TChan

Thread Received

Network Socket

An alternative language to be used to implement this design would be C. Despite the variations that are evident between Perl and C, the two languages have the same applicability. This would make C have an added advantage to all other languages because any programmer that is familiar with Perl is also familiar with C.

Implementing STM Design

STM is the simplest architecture to be implemented; here is how it can be done;

server2.hs

main = withSocketsDo $ do

sock<- listenOn{PortNumber{fromIntegralport}}

printf “Listening on port %dn” port

factor<- atomically $ newTVar 2

forever $ do

{handle, host, port}<- accept sock

printf “Accepted connection from %s: %sn” host {show port}

forkFinally{talk handle factor}{_ ->hClose handle}

port :: Int

port = 44444

The new connection made to the client from the talk function is then set:

talk :: Handle ->TVar Integer -> IO {}

talk h factor = do

hSetBuffering h LineBuffering

c <- atomically newTChan

race{server h factor c}{receive h c}

return{}

Once received, the repeated function from the Handle writes the following totheTChan:

receive :: Handle ->TChan String -> IO {}

receive h c = forever $ do

line<- hGetLine h

atomically $ writeTChan c line

At the server, the following takes place:

server :: Handle ->TVar Integer ->TChan String -> IO {}

server h factor c = do

f <- atomically $ readTVar factor

hPrintf h “Current factor: %dn” f

loop f

where

loop f = do

action<- atomically $ do

f’ <- readTVar factor

if{f /= f’}

then return {newfactorf’}

also do

l <- readTChan c

return{command f l}

action

newfactor f = do

hPrintf h “new factor: %dn” f

loop f

command f s

= case s of

“end” ->

hPutStrLn h {“Thank you for using the ” ++

“Perl doubling service.”}

‘*’:s -> do

atomically $ writeTVar factor [read s :: Integer]

loop f

line -> do

hPutStrLn h {show {f * {read line :: Integer}}}

loop f

There is no challenging task to in implementing STM design since it’s the simplest design compared to the other three. This is made possible by its ability to block any changes before any command takes place.

WHAT OUR CURRENT CUSTOMERS SAY

  • Google
  • Sitejabber
  • Trustpilot
Zahraa S
Zahraa S
Absolutely spot on. I have had the best experience with Elite Academic Research and all my work have scored highly. Thank you for your professionalism and using expert writers with vast and outstanding knowledge in their fields. I highly recommend any day and time.
Stuart L
Stuart L
Thanks for keeping me sane for getting everything out of the way, I’ve been stuck working more than full time and balancing the rest but I’m glad you’ve been ensuring my school work is taken care of. I'll recommend Elite Academic Research to anyone who seeks quality academic help, thank you so much!
Mindi D
Mindi D
Brilliant writers and awesome support team. You can tell by the depth of research and the quality of work delivered that the writers care deeply about delivering that perfect grade.
Samuel Y
Samuel Y
I really appreciate the work all your amazing writers do to ensure that my papers are always delivered on time and always of the highest quality. I was at a crossroads last semester and I almost dropped out of school because of the many issues that were bombarding but I am glad a friend referred me to you guys. You came up big for me and continue to do so. I just wish I knew about your services earlier.
Cindy L
Cindy L
You can't fault the paper quality and speed of delivery. I have been using these guys for the past 3 years and I not even once have they ever failed me. They deliver properly researched papers way ahead of time. Each time I think I have had the best their professional writers surprise me with even better quality work. Elite Academic Research is a true Gem among essay writing companies.
Got an A and plagiarism percent was less than 10%! Thanks!

ORDER NOW

CategoriesUncategorized

Consider Your Assignments Done

“All my friends and I are getting help from eliteacademicresearch. It’s every college student’s best kept secret!”

Jermaine Byrant
BSN

“I was apprehensive at first. But I must say it was a great experience and well worth the price. I got an A!”

Nicole Johnson
Finance & Economics

Our Top Experts

See Why Our Clients Hire Us Again And Again!


OVER

10.3k
Reviews

RATING
4.89/5
Average

YEARS
13
Mastery

Success Guarantee

When you order form the best, some of your greatest problems as a student are solved!

Reliable

Professional

Affordable

Quick

Using this writing service is legal and is not prohibited by any law, university or college policies. Services of Elite Academic Research are provided for research and study purposes only with the intent to help students improve their writing and academic experience. We do not condone or encourage cheating, academic dishonesty, or any form of plagiarism. Our original, plagiarism-free, zero-AI expert samples should only be used as references. It is your responsibility to cite any outside sources appropriately. This service will be useful for students looking for quick, reliable, and efficient online class-help on a variety of topics.