This is a simple Java Swing-based chat application that allows multiple clients to connect to a server and exchange messages in real-time. It uses a PostgreSQL database for user authentication and tracking online users.
- Server: The server listens for incoming connections from clients and manages client communication. It handles multiple clients simultaneously using separate threads.
- Client: Clients can connect to the server, send messages, and receive messages from other clients. The user interface is built using Java Swing.
- DataAccess: Manages user authentication and tracks online users in a PostgreSQL database.
To get started with the chat application, you'll need to set up the server, client, and database components.
The server class is responsible for handling incoming client connections and managing client communication. The Server
class listens on a specified port and creates a ServerSocket
to accept incoming connections.
The Client class represents a client connecting to the server. It sets up communication with the server through sockets and provides methods to send and receive messages. The user interface is built using Java Swing.
The DataAccess class is used for database-related operations. It connects to a PostgreSQL database with user credentials and provides methods for user authentication and tracking online users.
To use the chat application:
- Setup a postgres database according to the SQL dump and update the connection string to match your database.
- Compile and run the server.
- Compile and run the client(s).
- Clients can log in, send and receive messages in real-time.
- The server handles client connections and broadcasts messages to all connected clients.
I used this project as a small intro into the world of sockets and all that jazz. I will most likely revisit this project in the future once we touch on the networking subject in my studies. Also, this was an introduction to Java Swing for me so the code might be overly messy but it does the job. (For now) Doing this project I have learned way more about Sockets/Websockets and how the communication between them works. But there is still a lot of gray-areas which I do not understand. Overall, I felt that this was a fun small project to have and I will probably build a second version or update this in the future.
This project is licensed under the MIT License - see the LICENSE file for details.