This repository contains a basic implementation of a chat client-server application using Java. The project demonstrates networking concepts, including socket communication and multithreading.
- Client: A GUI-based chat client that allows users to send messages to a server.
- Server: A multi-threaded server that accepts connections from multiple clients and handles incoming messages.
- ReaderJob: A Runnable task that reads messages from the client socket and prints them to the console.
This file contains the implementation of the chat client. The client GUI includes a text field for input and a send button to transmit messages to the server.
Key Features:
- Establishes a connection to the server using a
SocketChannel
. - Sends messages typed in the text field to the server.
- Utilizes
Swing
components for the GUI.
public class Client {
// GUI components and networking setup
}
This file defines a Runnable task that reads messages from a BufferedReader and prints them to the console. It is used by the server to handle incoming messages from clients.
Key Features:
- Continuously reads messages from the client socket.
- Closes the reader upon completion or error.
public class ReaderJob implements Runnable {
// Reads messages from a BufferedReader and prints them
}
This file contains the implementation of the chat server. The server listens for incoming client connections and spawns a new ReaderJob thread for each connection to handle message reading.
Key Features:
- Binds to a specified port and accepts client connections.
- Uses a thread pool to manage multiple client connections concurrently.
- Reads messages from clients and can be extended to broadcast messages to all connected clients.
public class Server {
// Server setup and client connection handling
}
- Compile and run Server.java.
- The server will start and listen for connections on port 7213.
- Compile and run Client.java.
- A GUI window will appear where you can type and send messages.
- Java SE Development Kit (JDK) 8 or higher.
- Implement message broadcasting to all connected clients.
- Add a GUI component to display incoming messages on the client side.
- Improve error handling and user feedback in the GUI.
- Enhance security features such as authentication and encryption.