Skip to content

A network application with sockets and threads (Pthreads). The bank server keeps data for bank accounts and bank clients are connecting with the server to make transactions. The server has a thread pool and uses a thread for each client connection request

Notifications You must be signed in to change notification settings

billDrett/BankServer-socket-and-pthread-

Repository files navigation

BankServer(sockets, pthreads)

Introduction

A network application with sockets and threads (Pthreads). The bank server keeps data for bank accounts and bank clients are connecting to the server to make transactions. The server has a thread pool and uses a thread for each client connection request. To keep the data for each account is uses a threadsafe hashtable. I have implement my own list, queue and hashtable because i wasnt allowed to use stl in my class.

Compile

Make command to compile and make clean to remove all object files.

Run

For the server
./server -p < port > -s <thread_pool_size> -q <queue_size>

<port>: port number which will be used by the socket to receive connection from clients
<thread_pool_size>: The number of working threads in the thread pool
<queue_size>: The size of the queue

For the client
./client -h <server_host> -p <server_port> -i <command_file>
<server_host>: The address (name) of the server machine
<server_port> : The port of the server, so the client can connect to it
<command_file> : The file with the commands to the server

Example
./server -s 30 -q 100 -p 9002
./client -h localhost -p 9002 -i input.txt

Commands
  • add_account <init_ammount> <name> [delay]
  • Creates and account
  • add_transfer <amount> <src_name> <dst_name>
  • Transfers the amount from the src_name to dst_name account
  • add_multi_transfer <amount> <src_name> <dst_name1> <dst_name2> ... [delay]
  • Transfers to multiple accounts
  • print_balance <name>
  • Prints the balance of the account
  • print_multi_balance <name1> <name2> ...
  • Prints the multiple balances of the accounts
  • sleep <time>
  • The client sleeps for time seconds
  • exit
  • The client closes

    Implementation

    Queue for thread pool
    A thread safe circular queue has been implemented.

    Message form
    The message which are send between client and server use the first 4 bytes for the messageSize in bytes, 1 byte for space, and the message.

    HashTable
    The bankAccounts are kept in a hashTable.

    BankClient
    The bank client connect to the server, and reads one by one the commands from the file. The command is checked for any syntax errors and sended to the server, then the client waits for the response(success or not).

    BankServer
    The masterThread set up the socket. Then it creates the workerThreads and a queue for the incoming requests. For each new connection the connection is putted to the queue, a worker thread pops it out and does the commands. When it finishes it pops a new connection.

    To terminate the server use control-c

    About

    A network application with sockets and threads (Pthreads). The bank server keeps data for bank accounts and bank clients are connecting with the server to make transactions. The server has a thread pool and uses a thread for each client connection request

    Resources

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published