- Notifications
You must be signed in to change notification settings - Fork14
License
hridoy100/Java-Networking
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
_______.___________. ___ .______ / | | / \ | _ \ | (----`---| |----` / ^ \ | |_) | \ \ | | / /_\ \ | / .----) | | | / _____ \ | |\ \----.|_______/ |__| /__/ \__\ | _| `._____| .___________. __ __ __ _______.| || | | | | | / |`---| |----`| |__| | | | | (----` | | | __ | | | \ \ | | | | | | | | .----) | |__| |__| |__| |__| |_______/ .______ _______ .______ ______ _______. __ .___________. ______ .______ ____ ____ | _ \ | ____|| _ \ / __ \ / || | | | / __ \ | _ \ \ \ / / | |_) | | |__ | |_) | | | | | | (----`| | `---| |----`| | | | | |_) | \ \/ / | / | __| | ___/ | | | | \ \ | | | | | | | | | / \_ _/ | |\ \----.| |____ | | | `--' | .----) | | | | | | `--' | | |\ \----. | | | _| `._____||_______|| _| \______/ |_______/ |__| |__| \______/ | _| `._____| |__|
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:
- ChatApp
- Improved Implementation - A multi-client chat application with improved code and comments.
- docs - Documentation and GitHub Pages website for the project.
- reader_writer_thread
- Improved Implementation - Demonstrates client-server communication using separate reader and writer threads with improved code and comments.
- simple_client_server_using_threading
- Improved Implementation - A simple client-server application with multithreading with improved code and comments.
- simpleclient_server_without_thread
- Improved Implementation - A basic client-server application without multithreading with improved code and comments.
- Threading
- Improved Implementation - Examples demonstrating various Java threading concepts with improved code and comments.
- Thread-Pooling
- Beginner, Intermediate, Expert - Examples demonstrating thread pooling concepts from beginner to expert level.
- 1. Step-by-step-learning
- Simple Client/Server - Basic client-server communication.
- Threading - Multi-threaded server handling multiple clients.
- Synchronization - Demonstrates thread synchronization with shared resources.
- Multi-User Chat Application - A complete multi-user chat application.
- Secured Chat Application - A multi-user chat application secured with SSL/TLS.
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.
- 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
- Run the server:In the same terminal, run the server using the following command:
java io.github.hridoy100.Server
- 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
- 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.
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.
- 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
- Run the server:In the same terminal, run the server using the following command:
java io.github.hridoy100.Server
- 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
- Interact with the application:You can now run multiple clients and they will all be able to connect to the server and send messages.
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.
- 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
- Run the server:In the same terminal, run the server using the following command:
java io.github.hridoy100.Server
- 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
- Interact with the application:The client and server can now send and receive messages simultaneously.
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 theRunnable
interface.Synchronization.java
: Illustrates how to use thesynchronized
keyword to prevent race conditions and ensure thread safety.PCBlockingQueue.java
,Producer.java
, andConsumer.java
: Implement a producer-consumer pattern using aBlockingQueue
to safely exchange data between threads.
Each of the Java files in this project can be run individually. For example, to run theSynchronization
example, navigate to theThreading/src
directory and use the following commands:
javac io/github/hridoy100/Synchronization.javajava 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 likelist
to see connected users andip
to get your IP address.
- 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
- Run the server:In the same terminal, run the server using the following command:
java io.github.hridoy100.ServerMain
- 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
- 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.
Here are some suggestions for further improvements to this repository:
- Add a build system: The current method of compiling and running the projects using
javac
andjava
is cumbersome. Consider using a build system likeMaven orGradle to automate the build process. - Add unit tests: There are no unit tests in the repository. Adding unit tests would help to ensure the correctness of the code and prevent regressions. Consider using a testing framework likeJUnit to write and run the tests.
- Refactor the code: The code in some of the projects could be refactored for clarity and efficiency. For example, the
ChatApp
project could be refactored to use a more object-oriented design. - Add comments: The code is not well-commented. Adding comments would make it easier to understand the code and its functionality.
- Use a logging framework: The current projects use
System.out.println
for logging. Consider using a logging framework likeLog4j orSLF4J to provide more flexible and configurable logging.
About
Resources
License
Uh oh!
There was an error while loading.Please reload this page.