Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

hridoy100/Java-Networking

Repository files navigation

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

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 thesimpleclient_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 thesimpleclient_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 thesimple_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 thesimple_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 thereader_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 thereader_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.

  • 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.

How to Run

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

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 likelist to see connected users andip to get your IP address.

How to Run

  1. Compile the code:Open a terminal and navigate to theChatApp/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 theChatApp/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 thelist command to see the list of connected users.

Further Improvements

Here are some suggestions for further improvements to this repository:

  • Add a build system: The current method of compiling and running the projects usingjavac 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, theChatApp 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 useSystem.out.println for logging. Consider using a logging framework likeLog4j orSLF4J to provide more flexible and configurable logging.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp