Skip to content

Latest commit

 

History

History
451 lines (354 loc) · 11.3 KB

File metadata and controls

451 lines (354 loc) · 11.3 KB

Socket Programming - Troubleshooting Guide

Overview

This comprehensive troubleshooting guide addresses common issues encountered when compiling, running, and testing the socket programming assignment across all three tasks.

General Issues

Java Installation and Configuration

Problem: "java is not recognized as an internal or external command"

Symptoms:

  • Command prompt cannot find java or javac
  • Environment variable issues

Diagnosis:

# Test Java installation
java -version
javac -version
echo %JAVA_HOME%
echo %PATH%

Solutions:

  1. Verify Java Installation:

    • Download and install Java 17 JDK from Oracle or OpenJDK
    • Ensure JDK (not just JRE) is installed
  2. Set Environment Variables:

    # Add to system PATH
    C:\Program Files\Java\jdk-17.0.14\bin
    
    # Set JAVA_HOME
    JAVA_HOME=C:\Program Files\Java\jdk-17.0.14
  3. Alternative Solutions:

    • Use full path to Java executables
    • Use IntelliJ IDEA's integrated compilation
    • Reinstall Java with automatic PATH configuration

Problem: Wrong Java Version

Symptoms:

  • Compilation errors related to language features
  • "Unsupported major.minor version" errors

Diagnosis:

java -version
# Should show version 17.x.x

Solutions:

  1. Update to Java 17 or higher
  2. Use IntelliJ to set the correct project SDK
  3. Remove older Java versions from PATH

Compilation Issues

Problem: "Cannot find symbol" errors

Symptoms:

error: cannot find symbol
  symbol:   class ServerSocket
  location: class PingPongServer

Diagnosis:

  • Missing import statements
  • Incorrect classpath
  • Package structure issues

Solutions:

  1. Add Missing Imports:

    import java.net.*;
    import java.io.*;
  2. Verify Package Structure:

    task2-ping-pong/src/
    ├── server/
    │   └── PingPongServer.java (package server;)
    └── client/
        └── PingPongClient.java (package client;)
    
  3. Use Correct Compilation Command:

    # From task2-ping-pong directory
    javac src/server/PingPongServer.java
    javac src/client/PingPongClient.java

Problem: Package declaration conflicts

Symptoms:

  • "The declared package does not match the expected package"
  • Class not found exceptions

Solutions:

  1. Match Package Declaration to Directory Structure:

    // In src/server/PingPongServer.java
    package server;
    
    // In src/client/PingPongClient.java  
    package client;
    
  2. Compile from Correct Directory:

    # Always compile from the task directory containing src/
    cd task2-ping-pong
    javac src/server/PingPongServer.java

Task-Specific Issues

Task 1: Hostname to IP Converter

Problem: "UnknownHostException" for valid domains

Symptoms:

  • Cannot resolve well-known domains like google.com
  • DNS resolution failures

Diagnosis:

# Test network connectivity
ping google.com
nslookup google.com

Solutions:

  1. Check Internet Connection: Verify network connectivity
  2. DNS Configuration:
    • Use public DNS servers (8.8.8.8, 1.1.1.1)
    • Flush DNS cache: ipconfig /flushdns
  3. Firewall Issues: Check Windows Firewall settings
  4. Proxy Settings: Configure proxy if required

Problem: Application hangs on startup

Symptoms:

  • Program starts but doesn't show prompt
  • No error messages displayed

Solutions:

  1. Check Console Output: Ensure welcome message displays
  2. Scanner Issues: Verify System.in is not redirected
  3. Thread Issues: Check for deadlocks in input handling

Task 2: Ping-Pong Application

Problem: "Address already in use" error

Symptoms:

java.net.BindException: Address already in use: bind

Diagnosis:

# Check what's using port 12345
netstat -an | findstr 12345

Solutions:

  1. Stop Previous Server Instance:

    • Use Ctrl+C to stop server gracefully
    • Kill process if necessary: Task Manager → End Process
  2. Wait for Port Release:

    • Wait 30–60 seconds after stopping server
    • TCP TIME_WAIT state needs to clear
  3. Use Different Port:

    java -cp src server.PingPongServer 8080
    java -cp src client.PingPongClient localhost 8080
  4. Check for Port Conflicts:

    • Avoid well-known ports (< 1024)
    • Check for other applications using the port

Problem: Client cannot connect to server

Symptoms:

  • "Connection refused" errors
  • "Connection timeout" errors

Diagnosis:

  1. Verify Server is Running:

    # Should see "Ping-Pong Server Started" message
  2. Check Network Connectivity:

    telnet localhost 12345
    # Should connect if server is running

Solutions:

  1. Start Server First: Always start server before client
  2. Check Hostname: Use localhost for local testing
  3. Firewall Configuration: Allow Java through Windows Firewall
  4. Port Verification: Ensure server and client use the same port

Problem: No response to ping messages

Symptoms:

  • Client sends "ping" but receives no "pong"
  • Messages appear to be dropped

Diagnosis:

  1. Check Server Logs: Look for message processing logs
  2. Verify Message Format: Ensure exact "ping" text
  3. Network Issues: Check for packet loss

Solutions:

  1. Case Sensitivity: Server handles case-insensitive ping
  2. Message Trimming: Server trims whitespace automatically
  3. Connection State: Verify the client is still connected
  4. Server Processing: Check server console for error messages

Task 3: Uppercase Converter

Problem: Special characters not converting properly

Symptoms:

  • International characters display as question marks
  • Encoding issues with accented characters

Diagnosis:

# Check system locale and encoding
chcp
# Should show code page (e.g., 65001 for UTF-8)

Solutions:

  1. Set Console Encoding:

    chcp 65001
    # Sets console to UTF-8
  2. IntelliJ Configuration:

    • File → Settings → Editor → File Encodings
    • Set all encodings to UTF-8
  3. JVM Encoding:

    java -Dfile.encoding=UTF-8 -cp src client.UppercaseClient

Problem: Long messages cause errors

Symptoms:

  • "Message too long" errors for valid input
  • Server rejects messages unexpectedly

Solutions:

  1. Check Message Length: Maximum 1024 characters
  2. Unicode Character Counting: Some characters count as multiple bytes
  3. Configuration: Modify MAX_MESSAGE_LENGTH if needed

Network and Connectivity Issues

Firewall Problems

Problem: Windows Firewall blocking connections

Symptoms:

  • Local connections work, remote connections fail
  • Intermittent connection issues

Solutions:

  1. Allow Java Through Firewall:

    • Windows Security → Firewall & Network Protection
    • Allow an app through firewall → Add Java
  2. Create Firewall Rules:

    • Add inbound rules for ports 12345 and 54321
    • Allow both TCP and UDP protocols
  3. Temporary Testing:

    • Temporarily disable Windows Firewall for testing
    • Remember to re-enable after testing

Network Configuration Issues

Problem: Cannot connect between different machines

Symptoms:

  • localhost connections work
  • Remote machine connections fail

Solutions:

  1. Use Correct IP Address:

    ipconfig
    # Find actual IP address, not localhost
  2. Network Discovery: Enable network discovery on Windows

  3. Router Configuration: Check router firewall settings

  4. VPN Issues: Disable VPN for local network testing

Performance and Resource Issues

Memory Problems

Problem: OutOfMemoryError

Symptoms:

  • Applications crash with memory errors
  • Slow performance with multiple clients

Solutions:

  1. Increase Heap Size:

    java -Xmx512m -cp src server.PingPongServer
  2. Monitor Memory Usage: Use Task Manager to monitor

  3. Resource Leaks: Check for unclosed sockets/streams

Thread Issues

Problem: Server becomes unresponsive

Symptoms:

  • Server stops accepting new connections
  • Existing clients cannot send messages

Diagnosis:

  1. Check Thread Count: Monitor active threads
  2. Deadlock Detection: Look for thread deadlocks
  3. Resource Exhaustion: Monitor system resources

Solutions:

  1. Restart Server: Stop and restart server application
  2. Resource Cleanup: Ensure proper connection cleanup
  3. Thread Limits: Monitor system thread limits

IntelliJ IDEA Specific Issues

Project Configuration Problems

Problem: Cannot run applications from IDE

Symptoms:

  • "Cannot find main class" errors
  • Run configurations not working

Solutions:

  1. Rebuild Project: Build → Rebuild Project

  2. Check Run Configurations:

    • Verify main class names
    • Check module assignments
    • Validate classpath settings
  3. Project Structure:

    • File → Project Structure
    • Verify module source roots
    • Check SDK configuration

Problem: Code completion not working

Symptoms:

  • No auto-completion for Java classes
  • Import statements not suggested

Solutions:

  1. Invalidate Caches: File → Invalidate Caches and Restart
  2. Rebuild Project: Clean and rebuild all modules
  3. Check SDK: Verify Java 17 SDK is properly configured

Testing and Validation Issues

Automated Testing Problems

Problem: Test sequences fail

Symptoms:

  • Automated tests don't complete
  • Inconsistent test results

Solutions:

  1. Timing Issues: Add delays between test operations
  2. Resource Cleanup: Ensure proper cleanup between tests
  3. Server State: Restart server between test runs

Integration Testing Issues

Problem: Multiple applications interfere

Symptoms:

  • One application affects another
  • Resource conflicts between tasks

Solutions:

  1. Port Separation: Use different ports for each task
  2. Resource Isolation: Run tasks in separate processes
  3. Timing Coordination: Start applications in correct order

Emergency Recovery Procedures

Complete Reset

If all else fails, follow these steps:

  1. Stop All Java Processes:

    • Task Manager → End all java.exe processes
    • Wait 30 seconds
  2. Clean Compilation:

    # Delete all .class files
    del /s *.class
    
    # Recompile everything
    compile-all.bat
  3. Reset Network:

    ipconfig /release
    ipconfig /renew
    ipconfig /flushdns
  4. Restart IDE: Close and restart IntelliJ IDEA

Getting Help

Information to Provide

When seeking help, include:

  1. Operating System: Windows 10 version
  2. Java Version: Output of java -version
  3. Error Messages: Complete error text
  4. Steps Taken: What you were trying to do
  5. Environment: IntelliJ vs command line

Useful Diagnostic Commands

# System information
java -version
javac -version
echo %JAVA_HOME%
echo %PATH%

# Network information
ipconfig /all
netstat -an | findstr :12345
netstat -an | findstr :54321

# Process information
tasklist | findstr java

This troubleshooting guide covers the most common issues encountered with the socket programming assignment. For issues not covered here, consult the task-specific documentation or seek assistance with the diagnostic information listed above.