CS476/576

Assignment #3

Due Midnight, Wednesday   Nov 23, 2011


Write a C/UNIX/TCP-Socket programs with the following descriptions:

NAME

gserver group server:

                Creates a  frontend process to manage five backend  processes for serving gclient processes.

gclient  -  group client:  get  service from  gserver.

 

SYNOPSIS

 

         gserver  <port>

         gclient   <host>  <port>  <1|0>

 

 

DESCRIPTION

 

The Figure below shows an overview of the gserver &  gclient:

 

ê The gclient process:

ü Creates a client socket C to connect to the frontend  at (<host>  <port>)

ü Creates a server socket S at the same port of  the client socket C.

ü Connects C to the frontend  and sends either 1 or 0.

§  1 indicates urgent service (it must get service)

§  0 indiactes normal service (gets service if there is a free backend process).

ü It receives back either 1 or 0.

§  1  a backend process will connect to it soon.

§  0  no backend is available and should exit..

ü After a backend process connects, the gclient:

§  Reads a  line from stdin , writes it to the backend process.

§  Receive the echoed line and displays it to the stdout.

§  Terminates if the user type CTRL-D  or the backend process closes the connection.

 

ê The gserver is composed of a frontend process and 5 backend processes.

 

v The frontend process:

ü Creates a server socket  and binds it <port>.

ü Creates five backend processes and connects to each with a pipe.

ü If it receives 0 from a gclient at ((host &  port):

§  if  there is a free backend process F: send 1 to the gclient  &  send  (host &  port) to F.  

§  if there is no free backend process, sends 0 to the gclient.

ü If  it receives 1 from a gclient

§  send 1 to the gclient

§  find a free backend process F, otherwise select a busy process F to abandon its current client.

§  send (host &  port) to F.

 

v Each backend process:

ü Creates a client socket to connect to any gclient.

ü When it gets a signal from the frontend process it reads the gclient  (host & port) from the pipe.

ü Connects to the gclient and offer its echo service (just send back any received line).

ü When the gclient closes the connection, signal the frontend process to change its status from busy to free.

 

*    See my implementation is under: /home/cs476/public_html/fall11/assignments/a3/wahab