Java-Networking

     _______.___________.    ___      .______      
    /       |           |   /   \     |   _  \     
   |   (----`---|  |----`  /  ^  \    |  |_)  |    
    \   \       |  |      /  /_\  \   |      /     
.----)   |      |  |     /  _____  \  |  |\  \----.
|_______/       |__|    /__/     \__\ | _| `._____|
                                                   
.___________. __    __   __       _______.
|           ||  |  |  | |  |     /       |
`---|  |----`|  |__|  | |  |    |   (----`
    |  |     |   __   | |  |     \   \    
    |  |     |  |  |  | |  | .----)   |   
    |__|     |__|  |__| |__| |_______/    
                                          
.______       _______ .______     ______        _______. __  .___________.  ______   .______     ____    ____ 
|   _  \     |   ____||   _  \   /  __  \      /       ||  | |           | /  __  \  |   _  \    \   \  /   / 
|  |_)  |    |  |__   |  |_)  | |  |  |  |    |   (----`|  | `---|  |----`|  |  |  | |  |_)  |    \   \/   /  
|      /     |   __|  |   ___/  |  |  |  |     \   \    |  |     |  |     |  |  |  | |      /      \_    _/   
|  |\  \----.|  |____ |  |      |  `--'  | .----)   |   |  |     |  |     |  `--'  | |  |\  \----.   |  |     
| _| `._____||_______|| _|       \______/  |_______/    |__|     |__|      \______/  | _| `._____|   |__|
                                                                          

Java-Networking

This repository contains a collection of simple Java networking projects.

🚀 Contributing

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!

Acknowledgements

Acknowledging my BUET CSE course teacher, Professor Rifat Shahriyar for his invaluable teaching and guidance.

Project Folders

Here’s a list of the main project folders in this repository:

Projects

Simple Client-Server without Thread

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.

How to Run

  1. Compile the code: Open a terminal and navigate to the 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
    
  2. Run the server: In the same terminal, run the server using the following command:
    java io.github.hridoy100.Server
    
  3. Run the client: Open a new terminal and navigate to the simpleclient_server_without_thread/src directory. Then, run the client using the following command:
    java io.github.hridoy100.Client
    
  4. Interact with the application: Enter a message in the client terminal and press Enter. The server will respond with the uppercase version of the message, which will be displayed in the client terminal.

Simple Client-Server with Threading

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.

How to Run

  1. Compile the code: Open a terminal and navigate to the 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
    
  2. Run the server: In the same terminal, run the server using the following command:
    java io.github.hridoy100.Server
    
  3. Run the client: Open a new terminal and navigate to the simple_client_server_using_threading/src directory. Then, run the client using the following command:
    java io.github.hridoy100.Client
    
  4. Interact with the application: You can now run multiple clients and they will all be able to connect to the server and send messages.

Reader-Writer Thread

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.

How to Run

  1. Compile the code: Open a terminal and navigate to the 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
    
  2. Run the server: In the same terminal, run the server using the following command:
    java io.github.hridoy100.Server
    
  3. Run the client: Open a new terminal and navigate to the reader_writer_thread/src directory. Then, run the client using the following command:
    java io.github.hridoy100.Client
    
  4. Interact with the application: The client and server can now send and receive messages simultaneously.

Threading

This project contains a collection of examples demonstrating different concepts in Java threading.

How to Run

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

ChatApp

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.

How to Run

  1. Compile the code: Open a terminal and navigate to the ChatApp/src directory. Then, compile the Java files using the following command:
    javac io/github/hridoy100/*.java
    
  2. Run the server: In the same terminal, run the server using the following command:
    java io.github.hridoy100.ServerMain
    
  3. Run the client: Open a new terminal and navigate to the ChatApp/src directory. Then, run the client using the following command:
    java io.github.hridoy100.ClientMain
    
  4. Interact with the application: Enter a username and start sending messages to other users. You can use the list command to see the list of connected users.

Further Improvements

Here are some suggestions for further improvements to this repository: