Skip to content

Java Socket Programming - Hostname to IP converter, Ping-Pong client-server, and Uppercase message converter applications

License

Notifications You must be signed in to change notification settings

NMsby/socket-programming

Repository files navigation

Socket Programming

Java socket programming assignment for Distributed Systems.
It implements three network applications demonstrating client-server communication patterns, multi-threading, and network application development using Java 17.

Tasks

Task 1: Hostname to IP Converter

Simple utility program that converts hostnames to IP addresses using Java's InetAddress class.

Task 2: Ping-Pong Client-Server Application

Multithreaded server that responds with "pong" to "ping" messages while dropping other messages.

Task 3: Uppercase Message Converter

Client-server application where the server converts received messages to uppercase and returns them.

Technology Stack

  • Language: Java 17.0.14 LTS
  • IDE: IntelliJ IDEA
  • Operating System: Windows 10 (adaptable to other platforms)
  • Libraries: Standard Java libraries (java.net, java.io)
  • Character Encoding: UTF-8 for international support

Project Structure

socket-programming/
├── README.md                           # Main project documentation
├── .gitignore                          # Git ignore patterns
├── compile-all.bat                     # Compilation script
├── run-servers.bat                     # Server startup script
│
├── docs/                               # Comprehensive documentation
│   ├── compilation-guide.md            # Compilation and setup instructions
│   ├── troubleshooting.md              # Common issues and solutions
│   ├── examples.md                     # Usage examples and scenarios
│   ├── code-quality-review.md          # Code quality assessment
│   └── integration-analysis.md         # Cross-task integration analysis
│
├── task1-hostname-converter/           # Task 1: DNS resolution
│   ├── src/
│   │   └── HostnameToIP.java           # Main application class
│   └── docs/
│       ├── requirements.md             # Task requirements
│       ├── design.md                   # Design documentation
│       └── UserGuide.md                # User manual
│
├── task2-ping-pong/                    # Task 2: Client-server communication
│   ├── src/
│   │   ├── server/
│   │   │   └── PingPongServer.java     # Multi-threaded server
│   │   └── client/
│   │       └── PingPongClient.java     # Interactive client
│   └── docs/
│       ├── architecture.md             # System architecture
│       ├── protocol.md                 # Communication protocol
│       ├── client-usage.md             # Client usage guide
│       ├── run-configurations.md       # IDE configuration
│       └── usage.md                    # General usage guide
│
├── task3-uppercase-converter/          # Task 3: Text processing service
│   ├── src/
│   │   ├── server/
│   │   │   └── UppercaseServer.java    # Production-quality server
│   │   └── client/
│   │       └── UppercaseClient.java    # Feature-rich client
│   └── docs/
│       ├── design.md                   # Design documentation
│       └── workflow.md                 # Processing workflows
│
└── tests/                              # Comprehensive testing
    ├── task1/
    │   ├── TestCases.md                # Test cases and results
    │   ├── TestExecutionLog.md         # Execution logs
    │   └── PerformanceTest.md          # Performance analysis
    ├── task2/
    │   ├── IntegrationTestPlan.md      # Integration testing
    │   ├── TestExecutionLog.md         # Test results
    │   └── MultiClientTest.md          # Multi-client testing
    └── task3/
        ├── TestingPlan.md              # Comprehensive test plan
        ├── TestExecutionLog.md         # Detailed test results
        └── PerformanceResults.md       # Performance benchmarks

Getting Started

Prerequisites

  • Java 17.0.14 LTS or higher
  • IntelliJ IDEA (recommended)
  • Git for version control
  • Windows 10 (instructions adaptable for other OS)

Clone Repository

  git clone https://github.com/NMsby/socket-programming.git
  cd socket-programming

Compile all applications

  compile-all.bat

Start servers (opens separate windows)

  run-servers.bat

Running Individual Tasks

Task 1: Hostname to IP Converter

  cd task1-hostname-converter
  javac src/HostnameToIP.java
  java -cp src HostnameToIP

Task 2: Ping-Pong Application

  # Terminal 1 - Server
  cd task2-ping-pong
  javac src/server/PingPongServer.java
  java -cp src server.PingPongServer

  # Terminal 2 - Client
  javac src/client/PingPongClient.java
  java -cp src client.PingPongClient

Task 3: Uppercase Converter

  # Terminal 1 - Server
  cd task3-uppercase-converter
  javac src/server/UppercaseServer.java
  java -cp src server.UppercaseServer

  # Terminal 2 - Client
  javac src/client/UppercaseClient.java
  java -cp src client.UppercaseClient

Task Descriptions

Task 1: Hostname to IP Converter

Objective: Learn basic networking and DNS resolution

Features:

  • Interactive hostname input and IP address resolution
  • Support for IPv4 and IPv6 addresses
  • Multiple IP address handling
  • Comprehensive error handling
  • Address type classification

Key Learning: DNS resolution, InetAddress class, network error handling

Task 2: Ping-Pong Client-Server

Objective: Understand client-server architecture and protocols

Features:

  • Multi-threaded TCP server supporting concurrent clients
  • Case-insensitive ping detection with exact matching
  • Message filtering (only "ping" receives "pong" response)
  • Interactive client with automated testing
  • Comprehensive connection management

Key Learning: TCP sockets, multi-threading, protocol design, resource management

Task 3: Uppercase Message Converter

Objective: Build production-quality network applications

Features:

  • UTF-8 encoding for international character support
  • Rich interactive client with comprehensive commands
  • Detailed logging and monitoring capabilities
  • Performance optimization and error recovery
  • Configurable message length limits

Key Learning: Character encoding, production patterns, performance optimization

Testing and Validation

Comprehensive Testing Suite

  • Unit Testing: Individual component validation
  • Integration Testing: Cross-component functionality
  • Performance Testing: Response times and throughput
  • Load Testing: Concurrent client handling
  • Edge Case Testing: Error conditions and recovery

Test Results Summary

  • Task 1: 100% success rate with comprehensive DNS testing
  • Task 2: Multi-client support validated up to 50+ concurrent connections
  • Task 3: International character support verified with UTF-8 encoding
  • Overall: All performance targets exceeded with <10 ms average response times

Performance Metrics

Metric Task 1 Task 2 Task 3
Response Time <100ms <10ms <10ms
Concurrent Clients N/A 50+ 50+
Throughput N/A 200+ msg/s 200+ msg/s
Memory Usage <20MB <40MB <40MB
Success Rate 100% 100% 100%

Development Tools

IntelliJ IDEA Setup

  1. Open Project: File → Open → Select project directory
  2. Configure SDK: Project Structure → Project → Set Java 17
  3. Build Project: Build → Build Project
  4. Run Configurations: Pre-configured for each task component

Command Line Tools

  • Compilation Scripts: compile-all.bat for automated building
  • Server Management: run-servers.bat for concurrent server startup
  • Individual Compilation: Task-specific compilation commands

Documentation

Core Documentation

Task-Specific Documentation

Each task includes detailed documentation covering:

  • Requirements analysis and design decisions
  • Architecture and implementation details
  • Usage guides and examples
  • Testing procedures and results

Future Enhancements

Production Features

  • Authentication and authorization
  • TLS/SSL encryption support
  • Load balancing capabilities
  • Database integration
  • REST API endpoints
  • Web-based management interface

Educational Extensions

  • Additional protocol implementations
  • Performance monitoring dashboards
  • Container deployment (Docker)
  • Microservices architecture
  • Message queuing systems

Contributing

This is an academic project, but suggestions and improvements are welcome!

Author

Nelson Masbayi

  • Distributed Systems Assignment
  • Java 17 Socket Programming Implementation

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Java Socket Programming - Hostname to IP converter, Ping-Pong client-server, and Uppercase message converter applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published