Author: Conor Egan
This project is a Java-based simulation of an electronic food marketplace. It uses a multithreaded client-server architecture built with TCP sockets to allow multiple buyers to connect concurrently to a single seller and purchase items.
The system features:
- A thread-per-connection model on the server.
- Synchronized, atomic access to shared resources (market inventory) to prevent race conditions.
- A broadcast mechanism to notify all connected clients of market updates in real-time.
The project is organized using a standard Java package structure:
- FoodMarketplace/
- src/
- marketplace/
- SellerServer.java
- BuyerHandler.java
- Marketplace.java
- BuyerClient.java
- ServerListener.java
- Config.java
- marketplace/
- marketplace/
- config.properties
- README.md
- .gitignore
- src/
- Java Development Kit (JDK) 11 or later.
Open a terminal in the root FoodMarketplace directory and run the following command to compile all source files:
javac -d . src/marketplace/*.javaThis will create a marketplace directory in the root containing the compiled .class files.
In a new terminal, from the root FoodMarketplace directory, start the server:
java -cp . marketplace.SellerServerThe server will start and begin listening for client connections on the port specified in config.properties.
For each buyer you wish to simulate, open a new, separate terminal. From the root FoodMarketplace directory, run the following command:
java -cp . marketplace.BuyerClientA new client will connect to the server. You can now interact with the marketplace using the following commands in the client terminal:
- list: Shows the currently available item and stock.
- buy : Attempts to buy the specified quantity of the current item (e.g., buy 2).
- quit: Disconnects from the server.