A distributed shopping prototype implemented in Java using UDP, TCP, and multithreading.
The system allows clients to register, search for items, negotiate prices, and complete purchases through a custom communication protocol. A persistent central server coordinates interactions between buyers and sellers.
- Custom peer-to-peer shopping protocol over UDP (control messages) and TCP (transactions)
- Asynchronous message delivery using separate sending/receiving threads
- Fully custom message format (CSV-like), serialization, and parsing utilities
- Hardcoded server and client ports for simplified discovery
- Server spawns a new thread for each incoming UDP message
- Client uses independent threads for:
- CLI interaction
- UDP reception
- TCP inbound/outbound communication
- Timers and expiration checks
- Concurrency control using synchronized blocks and volatile fields
- Multiple item lifecycle states:
- lookingFor
- negotiating
- reserved
- found
- offering
- buying
- Server-side persistence of:
- Registered clients
- Item lists
- Current request number
- Custom serialization/deserialization for Items, Offers, and RegisteredClient
- Two-way TCP transaction between buyer and seller:
- INFORM_REQ / INFORM_RES exchange
- Payment validation
- Shipping confirmation
- Independent sender/receiver threads for reliability
- Java
- UDP + TCP sockets
- Java concurrency (threads, synchronized, volatile)
- File-based persistence
├── src/
│ ├── Client.java
│ ├── Server.java
│ ├── Item.java
│ ├── Offer.java
│ ├── RegisteredClient.java
│ ├── OneShotUDPClient.java
│ ├── TCPClient.java
│ ├── TCPServer.java
│ └── Utils.java
├── project.jar
└── README.txt
- REGISTER
- DEREGISTER
- LOOKING_FOR
- SEARCH
- OFFER
- ACCEPT
- REFUSE
- FOUND
- RESERVE
- BUY
- CANCEL
- CANCEL_BUY
- NOT_AVAILABLE
- INFORM_REQ
- INFORM_RES
- PAYMENT_SUCCESSFUL
- SHIPPING_INFO
javac src/*.java -d out
jar cfe project.jar Main -C out .
java -jar project.jar
Choose server when prompted.
java -jar project.jar
Provide:
- Server IP
- Desired client UDP port
- Desired client TCP port
Available through the client CLI:
- Register
- Search for items
- Make or respond to offers
- Buy items
- Cancel transactions
Testing performed across:
- Localhost (multiple terminals)
- Home LAN (multiple computers)
- University lab (separate physical machines)
Validated scenarios:
- Successful negotiation and purchase
- Offer timeout expiration
- Negotiation timeouts
- Concurrent buyers/sellers
- Cancelled transactions
- TCP binding issues on multi-homed systems
- Input interrupt handling using buffer + busy state
All test cases passed during the final demonstration.
- TCP client and server modules
- Inbound message handlers
- Timer logic (client & server)
- Outbound client message functions (register, offer, buy, cancel)
- Major server logic (message execution, negotiation, reservation, buy sequence)
- OneShotUDPClient implementation
- Item, Offer, RegisteredClient classes
- Serialization & persistency mechanisms
- Migration to global constants for protocol strings