_______.___________. ___ .______ / | | / \ | _ \ | (----`---| |----` / ^ \ | |_) | \ \ | | / /_\ \ | / .----) | | | / _____ \ | |\ \----. |_______/ |__| /__/ \__\ | _| `._____| .___________. __ __ __ _______. | || | | | | | / | `---| |----`| |__| | | | | (----` | | | __ | | | \ \ | | | | | | | | .----) | |__| |__| |__| |__| |_______/ .______ _______ .______ ______ _______. __ .___________. ______ .______ ____ ____ | _ \ | ____|| _ \ / __ \ / || | | | / __ \ | _ \ \ \ / / | |_) | | |__ | |_) | | | | | | (----`| | `---| |----`| | | | | |_) | \ \/ / | / | __| | ___/ | | | | \ \ | | | | | | | | | / \_ _/ | |\ \----.| |____ | | | `--' | .----) | | | | | | `--' | | |\ \----. | | | _| `._____||_______|| _| \______/ |_______/ |__| |__| \______/ | _| `._____| |__|
This repository contains a collection of simple Java networking projects.
Contributions are highly encouraged! If you have any suggestions, improvements, or bug reports, please feel free to open an issue or submit a pull request on GitHub. Your input helps make this project better!
Acknowledging my BUET CSE course teacher, Professor Rifat Shahriyar for his invaluable teaching and guidance.
Here’s a list of the main project folders in this repository:
This project demonstrates a basic client-server application where a client can send a message to the server, and the server will respond with the same message in uppercase. This project does not use threading, so it can only handle one client at a time.
simpleclient_server_without_thread/src
directory. Then, compile the Java files using the following command:
javac io/github/hridoy100/Server.java io/github/hridoy100/Client.java
java io.github.hridoy100.Server
simpleclient_server_without_thread/src
directory. Then, run the client using the following command:
java io.github.hridoy100.Client
This project is an extension of the previous one, with the addition of multithreading. This allows the server to handle multiple clients simultaneously. Each client connection is handled in a separate thread, so the server can remain responsive to new clients while processing existing ones.
simple_client_server_using_threading/src
directory. Then, compile the Java files using the following command:
javac io/github/hridoy100/Server.java io/github/hridoy100/Client.java
java io.github.hridoy100.Server
simple_client_server_using_threading/src
directory. Then, run the client using the following command:
java io.github.hridoy100.Client
This project demonstrates a more advanced client-server application where both the client and the server use separate threads for reading and writing. This allows for full-duplex communication, where the client and server can send and receive messages simultaneously.
reader_writer_thread/src
directory. Then, compile the Java files using the following command:
javac io/github/hridoy100/Server.java io/github/hridoy100/Client.java io/github/hridoy100/ReaderThread.java io/github/hridoy100/WriterThread.java
java io.github.hridoy100.Server
reader_writer_thread/src
directory. Then, run the client using the following command:
java io.github.hridoy100.Client
This project contains a collection of examples demonstrating different concepts in Java threading.
MainThread.java
: Demonstrates basic thread operations like getting the current thread and setting its name.RunnableThread.java
: Shows how to create and run a new thread by implementing the Runnable
interface.Synchronization.java
: Illustrates how to use the synchronized
keyword to prevent race conditions and ensure thread safety.PCBlockingQueue.java
, Producer.java
, and Consumer.java
: Implement a producer-consumer pattern using a BlockingQueue
to safely exchange data between threads.Each of the Java files in this project can be run individually. For example, to run the Synchronization
example, navigate to the Threading/src
directory and use the following commands:
javac io/github/hridoy100/Synchronization.java
java io.github.hridoy100.Synchronization
This project is a multi-client chat application that allows users to connect to a server, set a username, and send messages to other users. The server maintains a list of connected clients and forwards messages between them. It also supports commands like list
to see connected users and ip
to get your IP address.
ChatApp/src
directory. Then, compile the Java files using the following command:
javac io/github/hridoy100/*.java
java io.github.hridoy100.ServerMain
ChatApp/src
directory. Then, run the client using the following command:
java io.github.hridoy100.ClientMain
list
command to see the list of connected users.Here are some suggestions for further improvements to this repository:
javac
and java
is cumbersome. Consider using a build system like Maven or Gradle to automate the build process.ChatApp
project could be refactored to use a more object-oriented design.System.out.println
for logging. Consider using a logging framework like Log4j or SLF4J to provide more flexible and configurable logging.