A multithreaded client-server application in Java that demonstrates practical use of both UDP and TCP - using each protocol where it actually fits best - along with concurrent client handling via thread pools.
The Centralized Computing System (CCS) acts as a compute server: clients discover it on the network, connect, and send arithmetic operation requests (ADD, SUB, MUL, DIV), which the server computes and returns. The server supports multiple concurrent clients and periodically reposts live usage statistics.
Rather than picking one protocol for everything, this project uses each where its strengths matter:
-
UDP for service discovery - connectionless and fast, well suited to a quick broadcast-and-response handshake (
CCS DISCOVER->CCS FOUND) before a real connection is established. -
TCP for client communication - connection-oriented and reliable, ensuring requests and computed results are delivered accurately and in order once a client is talking to the server.
- Start the server:
java -jar CCS.jar <port>- Start one or more clients, pointed at the same port:
java -jar CCS.jar <port>- The client broadcasts a
CCS DISCOVERmessage over UDP. The server respondsCCS FOUND, and the client then opens a TCP connection to the server. - Once connected, the client sends requests in the form
OPER ARG1 ARG2(e.g.ADD 4 7), and the server responds with the computed result. - Multiple clients can connect and send requests concurrently - the server handles each on its own thread.
- Every 10 seconds, the server logs live statistics: number of connected clients, total requests handled, per-operation counts (ADD/SUB/MUL/DIV), invalid request count, and the running sum of all computed values.
- ServiceDiscoveryThread` - listens for UDP discovery broadcasts and responds to valid clients.
CommunicationWithClientThread- accepts incoming TCP connections and hands each client off to its own thread via a dedicated thread pool.- **
ClientThread- handles a single client's requests: validates input, computes the result, and returns the response. SendStatisticsThread- reports live server statistics on a fixed interval.- Shared statistics counters use
AtomicIntegerto stay thread-safe under concurrent access from multiple client threads.
- Java
java.net(sockets, datagrams)java.util.concurrent(thread pools,AtomicInteger)
- JDK installed
- Two or more terminal windows/machines on the same network for a realistic multi-client test
git clone https://github.com/dmytrozelinskyy/centralized-computing-system.git
# build with your usual javac/jar workflow, or via your IDE
java -jar CCS.jar <port>Then, in separate terminals, run the client the same way with the same port.
MIT