Question: ou are invited to implement using socket(), bind(), connect(), fork() etc. an e-shop orders from customers via internet. The eshop will have a list of
ou are invited to implement using socket(), bind(), connect(), fork() etc. an e-shop orders from customers via "internet".
The eshop will have a list of products for which the number of available pieces is limited.
"Customers" will submit the request to purchase the e-shop products, and if the products are available, the store will inform customer for the success of the order, the total charge and will keep products. Otherwise, it will inform the client that requested product does not exist.
The online store will have a specific processing time order (even 0.5 seconds). At this time, it will not accept any more orders.
Each customer will submit a series of orders with a difference e.g. 1 seconds between orders.
Once all orders are completed, the online store will issue one consolidated report in which the following will be described for each product information:
1) Product description
2) Number of purchase requests
3) Number of units sold
4) List of users not served (i.e. did not find the product available)
At the end of the report a summary message will be printed containing:
1) Total number of orders
2) Total number of successful orders
3) Total number of unsuccessful orders
4) Total earnings
Implementation Guidelines
You will implement the catalogue through a table (even a catalogue) in the parent process (server). The table will have a size of e.g. 20 different products. Each product will be a structure (struct) that you will implement and will contain at least the following fields: description, price, item_count. For each product set the item_count value to 2 (ie there are 2 available products with this description).
The parent process (parent) will run the e-shop task. The paternal process should initialize the catalogue table and initialize a socket to accept messages from clients via sockets. Through the sockets it will be possible to accept orders from customers (for an order, customers will write with write to the socket, and the server will read with read from the socket).
To be informed about the progress of the order, the reception will be used that you have already created (this is a two-way communication), in which the server will write (write) and from which the client will read (read) it message that will describe the result of the order (i.e. whether it found or not the requested product).
Order processing time will be 1 second. You can implement the processing time using the sleep() system call from the paternal process.
Clients will communicate with the eshop through internet sockets, according to what we have said in the laboratory. To check the program, you will create 5 different clients. Each customer will send 10 orders and then it will terminate its execution. Between orders it will wait 1 second. The wait can be implemented using the system call sleep(). For each order, it will run the rand() function to pick one random number between 0 and 20 (where 20 is the different products). As soon as he chooses the product, will put (write) its order in the slot and wait for it result of his order.
For clients it is necessary to use fork().
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
