Develop a shopping solution that has both client side and server side.
Server-side
• A console application should be enough; it prints each response to the output window before sending back to the client-side(s).
• When it first runs, at least five pre-defined products with random quantities (1-3) should be initialized. Which means products should be the same every time the server starts, and the quantities for each product should be randomized.
• At least 3 accounts should be created, each account has an account number and user's name.
• When the server is active, it should store ordering information to variable(s) (e.g., dictionaries, lists). The server does not have to store the ordering information to the local system, so once you shut down the server, all information can be disposed.
• The server should send back an appropriate response depending on the client's command. (Protocol below)
• The handler code should be separated from the user interface (i.e., in a separate class — similar to the examples available on the blackboard).
• The server must be able to talk with multiple clients at the same time.
Client-side
• The client-side should be a Windows Forms application, with an appropriate user interface. The user can select one product, then make the purchase. (quantity as one)
• When it first opens, a login form should appear with two input fields: hostname/IP and the account number. (localhost as the default value for the hostname)
• If the server cannot be found, the application should display an error message; if the server is active but login failed, a different error message should be displayed.
• Once the user successfully connects to the server, the application should get all product information (names and quantities), then show all information on the GUI.
• The user must be able to gracefully disconnect from the server. Upon disconnecting, the application should close. The application should gracefully disconnect when the form is closed.
• When the user makes the purchase, if the product is not available, the application should display an appropriate message stating that the product is no longer available.
• The application should be able to show current purchase orders.
• The server handler code should be separated from the user interface (i.e., in a separate class — similar to the examples on the blackboard).
Protocol standard for this project:
Client Command
Server Response
DISCONNECT
No response.
The server removes the client from the list of active clients. Both sides end the connection.
CONNECT:account_no
CONNECTED:user_name
The client has successfully connected with the specified account number. The server returns the connected client's name.
CONNECT_ERROR
The client's connection attempt is unsuccessful. The account_no is not valid.
GET_PRODUCTS
PRODUCTS: product_name1,quantity1|product_name2,quantity2|...
The server sends all product information (e.g. PRODUCTS:APPLE,2|ORANGE,1).
NOT_CONNECTED
The client is not currently connected.
GET_ORDERS
ORDERS:product_name1,quantity1,user_name|product_name2,quantity2,user_name|...
The server sends the purchase orders of the current client. (e.g. ORDERS:APPLE,1,John|ORANGE,1,Doe).
NOT_CONNECTED
The client is not currently connected.
PURCHASE:product_name
The product_name argument is one of the product names from the GET_PRODUCTS response.
NOT_AVAILABLE
The product is not available (i.e., is already purchased by another client) and cannot be purchased.
NOT_VALID
The specified product is not valid.
NOT_CONNECTED
The client is not currently connected.
The demo file Server-side output when booted and made purchases is as follows:
Press Q to shut down
CONNECT:1111
CONNECTED:John
GET_ORDERS
ORDERS:
GET_PRODUCTS
PRODUCTS:Apple,1|Orange,3|Pineapple,2|Printer,3|Keyboard,3|Shampoo,3
CONNECT:2222
CONNECTED:Chris
GET_ORDERS
ORDERS:
GET_PRODUCTS
PRODUCTS:Apple,1|Orange,3|Pineapple,2|Printer,3|Keyboard,3|Shampoo,3
PURCHASE:Apple
DONE
GET_ORDERS
ORDERS:Apple,1,Chris
PURCHASE:Apple
NOT_AVAILABLE
PURCHASE:Pineapple
DONE
GET_ORDERS
ORDERS:Apple,1,Chris|Pineapple,1,John