A simple number guessing game built in Java using client/server socket communication. The server generates a random number and the client attempts to guess it within a limited number of tries, receiving real-time feedback after each attempt.
- About the Project
- Features
- How It Works
- Tech Stack
- Installation & Usage
- Project Structure
- Contributing
- Contact
- License
This project is a practical implementation of socket programming in Java. It demonstrates how a server and a client can communicate over a network using TCP sockets, with the server hosting a number guessing game and the client interacting with it remotely.
- Developer: Haluk Can SARIÖZ
- Type: Console Application (Server-Client)
- Purpose: Learning Java socket programming and network communication
- Client-Server Architecture: The server runs the game logic while the client provides the user interface.
- Random Number Generation: The server picks a random number between 1 and 10 at the start of each game.
- Limited Guesses: The client has a maximum of 3 attempts to guess the correct number.
- Real-Time Feedback: After each guess, the server responds with:
Yukselt!(Go higher!) if the guess is too lowDusur!(Go lower!) if the guess is too highDogru(Correct!) if the guess is rightYanlis - Olmasi gereken rakam: X(Wrong - the correct number was X) if all attempts are used
- Input Validation: Out-of-range numbers (outside 1–10) cause the server to terminate the connection.
- The server starts and listens on port
7985. - The client connects to the server at
localhost:7985. - The server generates a random number (1–10) and sends an initial prompt to the client.
- The client prompts the user to enter a guess, which is sent back to the server.
- The server evaluates the guess and sends a result code:
1→ Correct2→ Too low (increase)3→ Too high (decrease)4→ Game over (out of attempts)
- The game ends when the client guesses correctly or runs out of attempts.
| Layer | Technology |
|---|---|
| Language | Java |
| Networking | java.net.ServerSocket, java.net.Socket |
| I/O | java.io.PrintWriter, java.io.BufferedReader, java.util.Scanner |
| Utilities | java.util.Random |
| Version Control | Git & GitHub |
- Java JDK 8+
- Git
1. Clone the repository:
git clone https://github.com/halukcansarioz/Socket-Guess-Game-Java.git2. Navigate to the project directory:
cd Socket-Guess-Game-Java3. Compile both files:
javac Server.java Client.java4. Start the server (in one terminal):
java Server5. Start the client (in another terminal):
java Client6. Play the game:
Follow the prompts in the client terminal to enter your guesses (1–10).
⚠️ Note: The server must be started before the client. Both programs run onlocalhost(port7985).
Socket-Guess-Game-Java/
├── Server.java # Server-side game logic
├── Client.java # Client-side user interface
├── .gitattributes # Git configuration file
└── README.md # Project documentation
Contributions, bug reports, and feature requests are welcome!
- Fork this repository.
- Create a Branch (
git checkout -b feature/NewFeature). - Make your changes and Commit (
git commit -m 'Add: New feature'). - Push your code (
git push origin feature/NewFeature). - Open a Pull Request.
Haluk Can Sarıöz
- GitHub: @halukcansarioz
- Email: halukcansarioz19@gmail.com
- LinkedIn: Haluk Can Sarıöz
If you found this project helpful, don't forget to ⭐ it!
This project is licensed under the MIT License.