Homework 1


Due Date

April 11th 2005: 5:00PM

Description

You will implement a client-server system which operates a bank. There will be a single server which will maintain a single account. Intially the account balance is 0. There can be many clients who can request service simultaneously from this server. The services are of three types:

  • Deposit : The client might make a deposit into the account and the account will be credited that much amount. The deposit must be a positive floating point number. The server will acknowledge successful deposit by returning the current balance to the client.
  • Withdraw : The client can make a withdrawal of some positive floating amount. The account will be debited that much amount. If the account does not have sufficient balance, then an error should be returned to the client, otherwise the current balance is returned.
  • Balance : The client can ask for the balance and the server should reply with the current account balance.

    Requirements

    All code must be written in C. Network communication will use reliable TCP sockets.

    Server

    The server will be called server and invoked as follows
     $ server -p port -d delay 
    The arguments can be specified in any order. To parse arguments, use getopt. See man 3 getopt for more details. By default if port is not specified then server will listen on port 8000. The delay is an integer which specifies the time in milliseconds required to complete the deposit/withdraw/balance operations. You will be holding the mutex lock during this delay. By default the delay is 100msec. Use usleep to implement delay (see man 3 usleep ) for details.

    Client

    The client will be called client and invoked as follows:
    $ client -h servername -p port -d deposit -w withdraw -b 
    
    The servername specifies which computer is running the server and is compulsory. If port is not specified, use port 8000. Only one of -d, -w and -b options can be specified. After the client is done, it should print the balance returned by the server on stdout or -1 if an error occurred.

    Other Issues