This project demonstrates a simple communication system between two players using Java sockets. The project includes two main scenarios:
- Running both players in the same Java process.
- Running each player in separate Java processes.
Java Project/
├── src/
│ └── player_communication/
│ ├── Player.java
│ ├── Player1.java
│ ├── Player2.java
│ └── Main.java
├── out/
├── run_same_process.bat
├── run_separate_processes.bat
└── README.md
- Java Development Kit (JDK) installed
- Windows OS
Player.java
This class handles the communication logic for each player.
Player1.java
This class initializes Player1 with specific parameters and starts its execution.
Player2.java
This class initializes Player2 with specific parameters and starts its execution.
Main.java
This class is used to run both Player1 and Player2 in the same Java process using separate threads.
run_same_process.bat
This batch script is used to compile the Java classes and run both Player1 and Player2 in the same Java process.
run_separate_processes.bat
This batch script is used to compile the Java classes and run Player1 and Player2 in separate command prompt windows.
- Ensure that the ports (5001 and 5002) used by the players are not in use by other applications to avoid
java.net.BindException: Address already in use
errors. - If you encounter issues with ports being in use, you may need to free the ports by stopping any applications that are using them.
- Open a terminal or command prompt.
- Navigate to the project directory.
- Compile the Java files and run the main class using the batch script:
run_same_process.bat
- Open a terminal or command prompt.
- Navigate to the project directory.
- Compile the Java files and run the players in separate command prompt windows using the batch script:
run_separate_processes.bat