Question: Write in C++ Please. The Assignment You will write two programs, a server and a client. The server creates a socket in the Internet domain

Write in C++ Please.

The Assignment You will write two programs, a server and a client. The server creates a socket in the Internet domain bound to port SERVER_PORT (a constant you should define in both programs, you may use last 4 digits of your UM-ID to get a unique port number). The server receives requests through this socket, acts on those requests, and returns the results to the requester. The client will also create a socket in the Internet domain, send requests to the SERVER_PORT of a computer specified on the command-line, and receive responses through this socket from a server. 3 Only your server should create, read, write, update, or delete records into/from the text file or SQLite database. Once the server has started, it should check if there is at least one user, if there are no users the server should create one user manually or using code with, say, $100 balance. Then the server should wait for the connection requests from a client. Your client operates by sending one of the following commands: BUY, SELL, BALANCE, LIST, SHUDOWN, QUIT commands to the server. You should create a client that is able to send any of the commands above and allows a user to specify which of the commands the client should send to the server. The details of the protocol depend on the command the client sends to the server. BUY Buy an amount of stocks. A client sends the ASCII string "BUY" followed by a space, followed by a stock_symbol, followed by a space, followed by a stock_amount, followed by a space, followed by the price per stock, followed by a User_ID, and followed by the newline character (i.e., ' '). When the server receives a BUY command from a client, the server should handle the operation by calculating the stock price and deducting the stock price from the user's balance, a new record in the Stocks table is created or updated if one does exist. If the operation is successful return a message to the client with "200 OK", the new usd_balance and new stock_balance; otherwise, an appropriate message should be displayed, e.g.: Not enough balance, or user1 doesn't exist, etc. SELL SELL an amount of stock. A client sends the ASCII string "BUY" followed by a space, followed by a stock_symbol, followed by a space, followed by stock price, followed by a space, followed by a stock_amount, followed by a space, followed by a User_ID, and followed by the newline character (i.e., ' '). 4 When the server receives a SELL command from a client, the server should handle the operation by calculating the stock price and deposit the stock price to the user balance. If the operation is successful return a message to the client with "200 OK", the new usd_balance and new stock_balance. LIST List all records in the Stocks table/file. BALANCE Display the USD balance for user 1 5 SHUTDOWN The SHUTDOWN command, which is sent from the client to the server, is a single line message that allows a user to shutdown the server. A user that wants to shutdown the server should send the ASCII string "SHUTDOWN" followed by the newline character (i.e., ' '). Upon receiving the SHUTDOWN command, the server should return the string "200 OK" (terminated with a newline), close all open sockets and database connection, and then terminate. QUIT Only terminate the client. The client exits when it receives the confirmation message from the server.

Requirements The following items are required for full credit (100%): Implement all 6 commands: BUY, SELL, LIST, BALANCE, QUIT, SHUTDOWN After BUY and SELL the Stocks table/file and Users table/file should be updated Both the server and client should be able to run on any UMD login servers. Make sure that you do sufficient error handling such that a user can't crash your server. For instance, what will you do if a user provides invalid input? The server IP address should be a command line parameter for the client program. The server should print out all messages received from clients on the screen. When the previous client exits, the server should allow the next client to connect.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!