A client-server chat application developed in Java using sockets, multithreading, object streams, and a graphical user interface built with Java Swing.
The project implements a basic real-time communication system where multiple clients can connect to a server, identify themselves, view connected users, and exchange messages through a graphical interface.
This project demonstrates the implementation of network communication between a server and multiple clients using Java sockets.
The server listens for incoming connections on a configurable port. Each connected client is handled by an independent thread, allowing multiple clients to communicate with the server concurrently.
The client application provides a graphical interface where users can:
- Connect to a server.
- Enter a username.
- View connected users.
- Select a message recipient.
- Send messages.
- Receive messages from other clients.
- Disconnect from the chat.
The server application provides a graphical interface that displays a log of connection and disconnection events.
- Client-server communication using TCP sockets.
- Multiple simultaneous client connections.
- Multithreaded server architecture.
- Individual thread for each connected client.
- Object serialization using
ObjectInputStreamandObjectOutputStream. - Graphical user interface using Java Swing.
- Configurable server IP address and communication port.
- Unique client identifiers.
- Contact list updated when users connect or disconnect.
- Direct messaging between connected clients.
- Server activity log.
- Connection and communication error handling.
- Java
- Java Swing
- Java Sockets
- TCP/IP
- Multithreading
ThreadServerSocketSocketObjectInputStreamObjectOutputStreamLinkedList- NetBeans GUI components
The application follows a client-server architecture.
┌─────────────────────┐
│ SERVER │
│ │
│ ServerSocket │
│ │ │
└─────────┼───────────┘
│
┌─────────────┼─────────────┐
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ Client 1 │ │ Client 2 │ │ Client 3 │
│ │ │ │ │ │
│ Socket │ │ Socket │ │ Socket │
└────────────┘ └────────────┘ └────────────┘
The server maintains a collection of connected clients. Each client connection is handled by an instance of HiloCliente, which runs independently in its own thread.
Java-Multithreaded-Chat-Client-Server/
│
├── src/
│ └── gui/
│ ├── Cliente.java
│ ├── HiloCliente.java
│ ├── Servidor.java
│ ├── VentanaC.java
│ └── VentanaS.java
│
├── assets/
│ └── images/
│ ├── server_interface.jpg
│ ├── client_interface.jpg
│ ├── multiple_clients.jpg
│ ├── message_exchange.jpg
│ └── server_log.jpg
│
├── README.md
├── LICENSE
└── .gitignore
Manages the server-side communication.
Its main responsibilities are:
- Creating the
ServerSocket. - Listening for incoming connections.
- Accepting client connections.
- Creating a
HiloClientefor each connection. - Maintaining the list of connected clients.
- Managing the server log.
Represents the communication thread assigned to an individual client.
Its responsibilities include:
- Listening for messages from the client.
- Processing connection requests.
- Processing disconnection requests.
- Forwarding messages to the appropriate recipient.
- Notifying other clients when a user connects or disconnects.
This class is one of the main components demonstrating multithreading in the project.
Handles the communication from the client side.
Its responsibilities include:
- Establishing the socket connection.
- Creating object input and output streams.
- Requesting connection to the server.
- Sending messages.
- Receiving messages.
- Processing server responses.
- Notifying the server when disconnecting.
Provides the graphical interface for the client.
The interface allows the user to:
- Configure the server IP.
- Configure the communication port.
- Enter a username.
- Select a recipient.
- Write messages.
- Send messages.
- View the conversation history.
Provides the graphical interface for the server.
It displays:
- Server initialization status.
- Client connections.
- Client disconnections.
- Server activity logs.
The application uses LinkedList<String> objects to represent the messages exchanged between clients and the server.
Different message types are identified by the first element of the list.
SOLICITUD_CONEXION
The client sends its requested username to the server.
CONEXION_ACEPTADA
The server returns the assigned client identifier and the list of currently connected users.
NUEVO_USUARIO_CONECTADO
Notifies existing clients that a new user has connected.
MENSAJE
Contains:
Message type
Sender
Recipient
Message
This information allows the server to forward the message to the selected client.
SOLICITUD_DESCONEXION
The client notifies the server that it is disconnecting.
USUARIO_DESCONECTADO
The server informs the remaining clients that a user has disconnected.
The server uses Java threads to handle multiple client connections.
When a client connects, the server creates a new HiloCliente object:
Client connection
│
▼
HiloCliente
│
▼
Independent thread
This allows the server to continue accepting new connections while existing clients remain connected and communicate simultaneously.
The client allows the following connection parameters to be configured:
Server IP
Communication Port
Username
The default configuration included in the project is:
IP: 127.0.0.1
Port: 10101
The server uses port:
10101
by default.
Run:
VentanaS.java
The application will request the communication port.
The default port is:
10101
Once the server starts successfully, the server window displays:
Inicializando el servidor... [Ok].
Run:
VentanaC.java
The client requests:
- Server IP
- Communication port
- Username
For a local test, use:
IP: 127.0.0.1
Port: 10101
Run VentanaC.java again to create additional clients.
Each client receives a unique identifier and appears in the contact list of the other connected clients.
Select a connected user from the recipient list, enter a message, and press:
Enviar
The server receives the message and forwards it to the selected recipient.
The server graphical interface confirms that the server has been successfully initialized and provides access to its activity log.
The client interface provides the conversation history, recipient selection, message field, and send button.
Multiple client instances can connect to the same server simultaneously.
Messages can be sent between connected clients through the server.
The server records client connection and disconnection events.
Client 1
│
│ SOLICITUD_CONEXION
▼
Server
│
│ CONEXION_ACEPTADA
▼
Client 1
Client 2
│
│ SOLICITUD_CONEXION
▼
Server
│
├──► Client 1: NUEVO_USUARIO_CONECTADO
│
└──► Client 2: CONEXION_ACEPTADA
Client 1
│
│ MENSAJE
▼
Server
│
│ Forward message
▼
Client 2
The application includes basic handling for communication errors such as:
- Unknown server host.
- Invalid IP address.
- Invalid communication port.
- Server unavailable.
- Lost client-server communication.
- Socket closing errors.
- Object communication errors.
The graphical interfaces display appropriate messages when connection problems occur.
This project demonstrates several fundamental programming and computer networking concepts:
- Client-server architecture.
- TCP socket communication.
- Network programming in Java.
- Multithreading.
- Concurrent client management.
- Object serialization.
- Input and output streams.
- Graphical user interfaces.
- Event-driven programming.
- Message routing.
- Connection management.
This project is intended as an academic implementation of a client-server chat application.
The current implementation does not include:
- User authentication.
- Message encryption.
- Persistent message storage.
- Database integration.
- File transfer.
- Group conversations.
- End-to-end encryption.
This project is distributed under the MIT License.
See the LICENSE file for more information.
Luis Alva
Java project focused on network communication, sockets, multithreading, and graphical user interfaces.




