This comprehensive troubleshooting guide addresses common issues encountered when compiling, running, and testing the socket programming assignment across all three tasks.
Symptoms:
- Command prompt cannot find
javaorjavac - Environment variable issues
Diagnosis:
# Test Java installation
java -version
javac -version
echo %JAVA_HOME%
echo %PATH%Solutions:
-
Verify Java Installation:
- Download and install Java 17 JDK from Oracle or OpenJDK
- Ensure JDK (not just JRE) is installed
-
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
-
Alternative Solutions:
- Use full path to Java executables
- Use IntelliJ IDEA's integrated compilation
- Reinstall Java with automatic PATH configuration
Symptoms:
- Compilation errors related to language features
- "Unsupported major.minor version" errors
Diagnosis:
java -version
# Should show version 17.x.xSolutions:
- Update to Java 17 or higher
- Use IntelliJ to set the correct project SDK
- Remove older Java versions from PATH
Symptoms:
error: cannot find symbol
symbol: class ServerSocket
location: class PingPongServer
Diagnosis:
- Missing import statements
- Incorrect classpath
- Package structure issues
Solutions:
-
Add Missing Imports:
import java.net.*; import java.io.*;
-
Verify Package Structure:
task2-ping-pong/src/ ├── server/ │ └── PingPongServer.java (package server;) └── client/ └── PingPongClient.java (package client;) -
Use Correct Compilation Command:
# From task2-ping-pong directory javac src/server/PingPongServer.java javac src/client/PingPongClient.java
Symptoms:
- "The declared package does not match the expected package"
- Class not found exceptions
Solutions:
-
Match Package Declaration to Directory Structure:
// In src/server/PingPongServer.java package server; // In src/client/PingPongClient.java package client; -
Compile from Correct Directory:
# Always compile from the task directory containing src/ cd task2-ping-pong javac src/server/PingPongServer.java
Symptoms:
- Cannot resolve well-known domains like google.com
- DNS resolution failures
Diagnosis:
# Test network connectivity
ping google.com
nslookup google.comSolutions:
- Check Internet Connection: Verify network connectivity
- DNS Configuration:
- Use public DNS servers (8.8.8.8, 1.1.1.1)
- Flush DNS cache:
ipconfig /flushdns
- Firewall Issues: Check Windows Firewall settings
- Proxy Settings: Configure proxy if required
Symptoms:
- Program starts but doesn't show prompt
- No error messages displayed
Solutions:
- Check Console Output: Ensure welcome message displays
- Scanner Issues: Verify System.in is not redirected
- Thread Issues: Check for deadlocks in input handling
Symptoms:
java.net.BindException: Address already in use: bind
Diagnosis:
# Check what's using port 12345
netstat -an | findstr 12345Solutions:
-
Stop Previous Server Instance:
- Use Ctrl+C to stop server gracefully
- Kill process if necessary: Task Manager → End Process
-
Wait for Port Release:
- Wait 30–60 seconds after stopping server
- TCP TIME_WAIT state needs to clear
-
Use Different Port:
java -cp src server.PingPongServer 8080 java -cp src client.PingPongClient localhost 8080
-
Check for Port Conflicts:
- Avoid well-known ports (< 1024)
- Check for other applications using the port
Symptoms:
- "Connection refused" errors
- "Connection timeout" errors
Diagnosis:
-
Verify Server is Running:
# Should see "Ping-Pong Server Started" message -
Check Network Connectivity:
telnet localhost 12345 # Should connect if server is running
Solutions:
- Start Server First: Always start server before client
- Check Hostname: Use
localhostfor local testing - Firewall Configuration: Allow Java through Windows Firewall
- Port Verification: Ensure server and client use the same port
Symptoms:
- Client sends "ping" but receives no "pong"
- Messages appear to be dropped
Diagnosis:
- Check Server Logs: Look for message processing logs
- Verify Message Format: Ensure exact "ping" text
- Network Issues: Check for packet loss
Solutions:
- Case Sensitivity: Server handles case-insensitive ping
- Message Trimming: Server trims whitespace automatically
- Connection State: Verify the client is still connected
- Server Processing: Check server console for error messages
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:
-
Set Console Encoding:
chcp 65001 # Sets console to UTF-8 -
IntelliJ Configuration:
- File → Settings → Editor → File Encodings
- Set all encodings to UTF-8
-
JVM Encoding:
java -Dfile.encoding=UTF-8 -cp src client.UppercaseClient
Symptoms:
- "Message too long" errors for valid input
- Server rejects messages unexpectedly
Solutions:
- Check Message Length: Maximum 1024 characters
- Unicode Character Counting: Some characters count as multiple bytes
- Configuration: Modify MAX_MESSAGE_LENGTH if needed
Symptoms:
- Local connections work, remote connections fail
- Intermittent connection issues
Solutions:
-
Allow Java Through Firewall:
- Windows Security → Firewall & Network Protection
- Allow an app through firewall → Add Java
-
Create Firewall Rules:
- Add inbound rules for ports 12345 and 54321
- Allow both TCP and UDP protocols
-
Temporary Testing:
- Temporarily disable Windows Firewall for testing
- Remember to re-enable after testing
Symptoms:
- localhost connections work
- Remote machine connections fail
Solutions:
-
Use Correct IP Address:
ipconfig # Find actual IP address, not localhost -
Network Discovery: Enable network discovery on Windows
-
Router Configuration: Check router firewall settings
-
VPN Issues: Disable VPN for local network testing
Symptoms:
- Applications crash with memory errors
- Slow performance with multiple clients
Solutions:
-
Increase Heap Size:
java -Xmx512m -cp src server.PingPongServer
-
Monitor Memory Usage: Use Task Manager to monitor
-
Resource Leaks: Check for unclosed sockets/streams
Symptoms:
- Server stops accepting new connections
- Existing clients cannot send messages
Diagnosis:
- Check Thread Count: Monitor active threads
- Deadlock Detection: Look for thread deadlocks
- Resource Exhaustion: Monitor system resources
Solutions:
- Restart Server: Stop and restart server application
- Resource Cleanup: Ensure proper connection cleanup
- Thread Limits: Monitor system thread limits
Symptoms:
- "Cannot find main class" errors
- Run configurations not working
Solutions:
-
Rebuild Project: Build → Rebuild Project
-
Check Run Configurations:
- Verify main class names
- Check module assignments
- Validate classpath settings
-
Project Structure:
- File → Project Structure
- Verify module source roots
- Check SDK configuration
Symptoms:
- No auto-completion for Java classes
- Import statements not suggested
Solutions:
- Invalidate Caches: File → Invalidate Caches and Restart
- Rebuild Project: Clean and rebuild all modules
- Check SDK: Verify Java 17 SDK is properly configured
Symptoms:
- Automated tests don't complete
- Inconsistent test results
Solutions:
- Timing Issues: Add delays between test operations
- Resource Cleanup: Ensure proper cleanup between tests
- Server State: Restart server between test runs
Symptoms:
- One application affects another
- Resource conflicts between tasks
Solutions:
- Port Separation: Use different ports for each task
- Resource Isolation: Run tasks in separate processes
- Timing Coordination: Start applications in correct order
If all else fails, follow these steps:
-
Stop All Java Processes:
- Task Manager → End all java.exe processes
- Wait 30 seconds
-
Clean Compilation:
# Delete all .class files del /s *.class # Recompile everything compile-all.bat
-
Reset Network:
ipconfig /release ipconfig /renew ipconfig /flushdns
-
Restart IDE: Close and restart IntelliJ IDEA
When seeking help, include:
- Operating System: Windows 10 version
- Java Version: Output of
java -version - Error Messages: Complete error text
- Steps Taken: What you were trying to do
- Environment: IntelliJ vs command line
# 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 javaThis 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.