PROGRAM DESCRIPTION:

In this assignment, you will write two complete C programs to support a client/server model using Linux sockets. In particular, Server X is creating a Ponzi scheme where he has created a finite amount of 30 crypto currency units (similar to Bitcoin, Ethereum, Litecoin, etc.) whereby he is looking for investors to purchase his crypto currency for anywhere between $3,000 and $5,000, inclusively, depending on the current market price. Your program will develop a two-tiered purchasing system that will consist of a distributor (i.e., the server) that will provide services to "BUY" and SELL the crypto currency to two investors (i.e., the clients) as follows:

Server

  • The server will start with 30 units of the crypto currency and a balance of $0.00 of investments. These values will fluctuate as clients BUY and SELL the crypto currency.
  • When a client sends a "BUY" request to purchase a single crypto currency unit from the server, as long as the server has units of crypto currency to sell, he will generate a seeded, randomized price between $3,000 and $5,000, inclusively, due to the volatility of the crypto currency and sell that investor a crypto currency unit and send that integral value back to the client. If the server does not have any units of crypto currency for sale (which is a very real possibility as there will be more requests for units of crypto currency than there exists), then the server will respond with an integral value of 0, indicating no sale. In all cases, the server will send back an integer (i.e., either 0, or a integer between 3000 and 5000, inclusively).
  • When a client sends a "SELL" request to sell a single crypto currency unit to the server, the server will generate a seeded, randomized price between $3,000 and $5,000, inclusively, and then if the server has enough funds (i.e., his balance) to purchase back the crypto currency unit, then the server will send that integral value back to the client. Otherwise, if the server does not have the funds to buy back the crypto currency, the server will respond with an integral value of 0, indicating no sale. In all cases, the server will send back an integer (i.e., either 0, or a integer between 3000 and 5000, inclusively).
  • For all client requests and server responses, the server will print out a status of the current transaction that may be "modified" to make it more readable (see SAMPLE OUTPUT for examples of this). Additionally, the server will print out a final status after all client requests have been processed with the number of crypto currency units and final balance.
  • When no clients remain "connected" to the server, the server will complete its operations and shut down.

Clients (note that there are 2 clients, but 1 client source code)

  • Each client will start with 0 units of the crypto currency and a balance of $40,000. These values will fluctuate as each client BUYs and SELLs crypto currency units.
  • Each client will make 20 automated requests to the server according to the following:
    • If a client has a balance greater than 0, the client will issue a "BUY" request (i.e., the client will send the string BUY to the server). If the server returns a non-zero value (i.e., an integer between 3000 and 5000, inclusively), the client will subtract this purchase price from his balance and increment the number of crypto currency units he possesses by one. Otherwise, if the server returns a zero value, if the client has at least one crypto currency unit, he will send a SELL request to the server to sell his unit of crypto currency. If the client does not have at least one crypto currency unit at this point, he will forfeit his request.
    • If a client does not have a positive balance, the client will issue a "SEND" request (i.e., the client will send the string SELL to the server). If the server returns a non-zero value (i.e., an integer between 3000 and 5000, inclusively), the client will add this purchase price to his balance and decrement the number of crypto currency units he possesses by one.
    • Following each request, each client will "sleep" for one second, allowing for the various transactions to be processed.
  • When all of the client requests have been processed, the client will disconnect from the server. This process should be automated and executed within the code (not input from a user). Each client will print out a final status after all client requests have been processed with the number of crypto currency units and final balance.

Your program should run on the INET domain using SOCK_STREAM (i.e., TCP) sockets so that the server and each of the two clients execute on three different CSE machines at the same time. The server code will accept the port number to communicate on as an argument to the program, while the client code (again, two clients using the same code) will accept the hostname of the server and the agreed- upon port number to communicate on as arguments to the program.

Instructor's Note: After the SEC determined this was a Ponzi scheme, the agency issued a cease and desist order and all money invested was lost. This assignment is not based on actual events and any resemblance to such is purely coincidental.

SAMPLE OUTPUT (user input shown in bold green):

==> SERVER on cse04

Chriss120299@cosc04:~$ ./minor6svr usage: ./minor6svr port Chriss120299@cosc04:~ $ ./minor6svr 11800
[CLIENT
[SERVER 1]:
X]: BUY
Client
1
BUY
$4012.00
[CLIENT
[SERVER 2]:
X]: BUY
Client
2
BUY
$4337.00
[CLIENT 1]: BUY
[SERVER
[CLIENT [SERVER X]:
2]:
X]: Client BUY
Client 1

2 BUY

BUY $4846.00

$4973.00
[CLIENT
[SERVER 1]:
X]: BUY
Client
1
BUY
$4058.00
[CLIENT
[SERVER 2]:
X]: BUY
Client
2
BUY
$3336.00
[CLIENT
[SERVER 1]:
X]: BUY
Client
1
BUY
$3045.00
[CLIENT 2]: BUY
[SERVER [CLIENT
[SERVER X]:
1]:
X]: Client BUY
Client 2

1 BUY

BUY $3058.00

$4603.00
[CLIENT
[SERVER 2]:
X]: BUY
Client
2
BUY
$4856.00
[CLIENT
[SERVER 1]:
X]: BUY
Client
1
BUY
$3755.00
[CLIENT
[SERVER 2]:
X]: BUY
Client
2
BUY
$3207.00
[CLIENT 1]: BUY
[SERVER [CLIENT
[SERVER X]:
2]:
X]: Client BUY
Client 1

2 BUY

BUY $3058.00

$3404.00
[CLIENT
[SERVER 1]:
X]: BUY
Client
1
BUY
$3990.00
[CLIENT
[SERVER 2]:
X]: BUY
Client
2
BUY
$4197.00
[CLIENT
[SERVER 1]:
X]: BUY
Client
1
BUY
$3241.00
[CLIENT 2]: BUY
[SERVER [CLIENT
[SERVER X]:
1]:
X]: Client BUY
Client 2

1 BUY

BUY $4658.00

$4152.00
[CLIENT
[SERVER 2]:
X]: BUY
Client
2
BUY
$4741.00
[CLIENT
[SERVER 1]:
X]: BUY
Client
1
BUY
$3952.00
[CLIENT 2]: SELL
[SERVER X]: Client 2 SELL $3090.00 [CLIENT 1]: SELL
[SERVER X]: Client 1 SELL $4327.00 [CLIENT 2]: BUY
[SERVER X]: Client 2 BUY $4895.00 [CLIENT 1]: BUY
[SERVER X]: Client 1 BUY $3995.00

[CLIENT
[SERVER 2]:
X]: SELL
Client
2
SELL $4834.00
[CLIENT 1]: SELL
[SERVER
[CLIENT [SERVER X]:
2]:
X]: Client BUY
Client 1

2 SELL $4473.00

BUY $3680.00
[CLIENT
[SERVER 1]:
X]: BUY
Client
1
BUY $3531.00
[CLIENT
[SERVER 2]:
X]: SELL
Client
2
SELL $4261.00
[CLIENT
[SERVER 1]:
X]: SELL
Client
1
SELL $3746.00
[CLIENT 2]: BUY
[SERVER [CLIENT
[SERVER X]:
1]:
X]: Client BUY
Client 2

1 BUY $4543.00

BUY $3154.00
[CLIENT
[SERVER 2]:
X]: SELL
Client
2
SELL $3591.00
[CLIENT
[SERVER 1]:
X]: SELL
Client
1
SELL $4072.00
[CLIENT
[SERVER 2]:
X]: BUY
Client
2
BUY $3770.00
[CLIENT 1]: BUY
[SERVER [CLIENT
[SERVER X]:
2]:
X]: Client SELL
Client 1

2 BUY $3485.00

SELL $3674.00
[CLIENT
[SERVER 1]:
X]: SELL
Client
1
SELL $3828.00
[CLIENT
[SERVER 2]:
X]: BUY
Client
2
BUY $3087.00

[SERVER X]: CRYPTO 10 units BALANCE: $77723.00

==> SAMPLE: CLIENT 1 on cse05

Chriss120299@cosc04:~$ ./minor6cli
usage ./minor6cli hostname port Chriss120299@cosc04:~$ ./minor6cli cse04 11800
[CLIENT]:
[CLIENT]:
[SERVER]: BALANCE = BUY
BUY PRICE $40000

$4012.00
[CLIENT]:
[CLIENT]: BALANCE =
BUY $35988
[SERVER]: BUY PRICE $4846.00
[CLIENT]:
[CLIENT]:
[SERVER]: BALANCE = BUY
BUY PRICE $31142

$4058.00
[CLIENT]: BALANCE = $27084
[CLIENT]:
[SERVER]: BUY
BUY PRICE
$3045.00
[CLIENT]:
[CLIENT]:
[SERVER]: BALANCE = BUY
BUY PRICE $24039

$4603.00
[CLIENT]:
[CLIENT]:
[SERVER]: BALANCE = BUY
BUY PRICE $19436

$3755.00

[CLIENT]: BALANCE = $15681 [CLIENT]: BUY
[SERVER]: BUY PRICE $3058.00 [CLIENT]: BALANCE = $12623 [CLIENT]: BUY
[SERVER]: BUY PRICE $3990.00 [CLIENT]: BALANCE = $8633 [CLIENT]: BUY
[SERVER]: BUY PRICE $3241.00 [CLIENT]: BALANCE = $5392 [CLIENT]: BUY
[SERVER]: BUY PRICE $4152.00 [CLIENT]: BALANCE = $1240 [CLIENT]: BUY
[SERVER]: BUY PRICE $3952.00 [CLIENT]: BALANCE = -$2712 [CLIENT]: SELL
[SERVER]: SELL PRICE $4327.00 [CLIENT]: BALANCE = $1615 [CLIENT]: BUY
[SERVER]: BUY PRICE $3995.00 [CLIENT]: BALANCE = -$2380 [CLIENT]: SELL
[SERVER]: SELL PRICE $4473.00 [CLIENT]: BALANCE = $2093 [CLIENT]: BUY
[SERVER]: BUY PRICE $3531.00 [CLIENT]: BALANCE = -$1438 [CLIENT]: SELL
[SERVER]: SELL PRICE $3746.00 [CLIENT]: BALANCE = $2308 [CLIENT]: BUY
[SERVER]: BUY PRICE $3154.00 [CLIENT]: BALANCE = -$846 [CLIENT]: SELL
[SERVER]: SELL PRICE $4072.00 [CLIENT]: BALANCE = $3226 [CLIENT]: BUY
[SERVER]: BUY PRICE $3485.00 [CLIENT]: BALANCE = -$259 [CLIENT]: SELL
[SERVER]: SELL PRICE $3828.00

[CLIENT]: CRYPTO 10 units BALANCE: $3569.00

==> SAMPLE: CLIENT 2 on cse06

Chriss120299@cosc04:~$ ./minor6cli cse04 11800
[CLIENT]: BALANCE =
[CLIENT]: BUY $40000
[SERVER]: BUY PRICE $4337.00
[CLIENT]: BALANCE = $35663
[CLIENT]: BUY
[SERVER]: BUY PRICE
$4973.00
[CLIENT]: BALANCE = $30690
[CLIENT]: BUY

[SERVER]: BUY PRICE $3336.00 [CLIENT]: BALANCE = $27354 [CLIENT]: BUY
[SERVER]: BUY PRICE $3058.00 [CLIENT]: BALANCE = $24296 [CLIENT]: BUY
[SERVER]: BUY PRICE $4856.00 [CLIENT]: BALANCE = $19440 [CLIENT]: BUY
[SERVER]: BUY PRICE $3207.00 [CLIENT]: BALANCE = $16233 [CLIENT]: BUY
[SERVER]: BUY PRICE $3404.00 [CLIENT]: BALANCE = $12829 [CLIENT]: BUY
[SERVER]: BUY PRICE $4197.00 [CLIENT]: BALANCE = $8632 [CLIENT]: BUY
[SERVER]: BUY PRICE $4658.00 [CLIENT]: BALANCE = $3974 [CLIENT]: BUY
[SERVER]: BUY PRICE $4741.00 [CLIENT]: BALANCE = -$767 [CLIENT]: SELL
[SERVER]: SELL PRICE $3090.00 [CLIENT]: BALANCE = $2323 [CLIENT]: BUY
[SERVER]: BUY PRICE $4895.00 [CLIENT]: BALANCE = -$2572 [CLIENT]: SELL
[SERVER]: SELL PRICE $4834.00 [CLIENT]: BALANCE = $2262 [CLIENT]: BUY
[SERVER]: BUY PRICE $3680.00 [CLIENT]: BALANCE = -$1418 [CLIENT]: SELL
[SERVER]: SELL PRICE $4261.00 [CLIENT]: BALANCE = $2843 [CLIENT]: BUY
[SERVER]: BUY PRICE $4543.00 [CLIENT]: BALANCE = -$1700 [CLIENT]: SELL
[SERVER]: SELL PRICE $3591.00 [CLIENT]: BALANCE = $1891 [CLIENT]: BUY
[SERVER]: BUY PRICE $3770.00 [CLIENT]: BALANCE = -$1879 [CLIENT]: SELL
[SERVER]: SELL PRICE $3674.00 [CLIENT]: BALANCE = $1795 [CLIENT]: BUY
[SERVER]: BUY PRICE $3087.00

[CLIENT]: CRYPTO 10 units BALANCE: -$1292.00

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.