Skip to content

danielaX21/Math-Server-Client-Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Math Server-Client Application

Project Overview

This project is a client-server application that performs basic mathematical operations over a network. The server listens for client connections, receives mathematical operation requests, processes them, and sends back the computed results. The client sends requests and receives responses from the server, making it a simple yet effective demonstration of socket programming in Java.

This project was developed as part of a university assignment where the base code was already provided. Additional improvements and modifications were made to enhance functionality and demonstrate a deeper understanding of network programming.


The Application Handles:

  • Establishing a TCP connection between a client and server.
  • Receiving and parsing mathematical operation requests from clients.
  • Performing basic arithmetic operations (addition, subtraction, multiplication, division).
  • Sending results back to the client over the network.
  • Handling errors such as invalid operations and division by zero.

How It Works

Communication & Processing

  1. Server Initialization
    • The server starts and listens for incoming client connections on a specified port.
    • Once a client connects, the server reads input requests.
  2. Client Requests
    • The client sends a request in the format: OPERATION number1 number2 (e.g., ADD 5 3).
    • Supported operations: ADD, SUB, MUL, DIV.
  3. Server Response
    • The server processes the request and performs the corresponding arithmetic operation.
    • The result is sent back to the client.
    • If an invalid request is received, an error message is returned.

Skills Applied in This Project

  • Java Socket Programming (Client-Server Communication)
  • Multithreading & Networking (Handling multiple client requests)
  • String Parsing & Exception Handling (Validating and processing user inputs)
  • Error Handling & Fault Tolerance (Handling invalid inputs and division by zero)

Technologies & Components Used

  • Java (Core programming language)
  • TCP Sockets (Client-Server communication protocol)
  • I/O Streams (BufferedReader, PrintWriter for data exchange)
  • Basic Arithmetic Operations (Addition, Subtraction, Multiplication, Division)

How to Run the Project

  1. Compile the Java files
    javac MathServer.java MathClient.java
  2. Start the Server
    java MathServer <port_number>
    • Example: java MathServer 5000
  3. Run the Client
    java MathClient <host> <port_number>
    • Example: java MathClient localhost 5000
  4. Send Requests from the Client
    • Example input: ADD 10 5
    • Expected response: Result: 15.0
    • Example invalid input: DIV 10 0
    • Expected response: Error: Division by zero

Real-World Applications – Why This Project is Important

This project provides a fundamental understanding of network communication and client-server interaction, applicable in:

  • Distributed Computing – Processing requests across networked systems.
  • Cloud-based API Services – Structuring data exchange between remote applications.
  • Real-time Communication Systems – Handling requests in web applications.

About

Java application that performs basic mathematical operation over a network

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages