/java_socket_chat

The real-time chat application, built using Java Socket API, that allows multiple clients to connect to a server and communicate with each other

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Java Socket Chat

This is a chat application that allows multiple clients to connect to a server and communicate with each other in real-time.

Client

The Client class represents the client-side of the chat application. It has the following methods:

  • sendMessage: This method allows the client to send messages to the server.
  • listenForMessage: This method starts a new thread that listens for incoming messages from the server and prints them to the console.
  • closeEverything: This method closes all resources (socket, buffered reader, and buffered writer) used by the client.

The main method of the Client class creates a new socket and connects to the server at localhost on port Config.ROOM_PORT. It then creates a new Client object and starts two threads: one for sending messages and another for listening for messages from the server.

ClientHandler

The ClientHandler class represents the server-side of the chat application. It has the following methods:

  • broadcastMessage: This method sends a message to all other clients connected to the server, except for the client that sent the message.

The ClientHandler class also implements the Runnable interface, which means that it can be executed by a separate thread. The run method of the ClientHandler class listens for incoming messages from the client and broadcasts the message to all other clients connected to the server.

Config

The Config class contains constants that are used by both the client and the server. It has the following constant:

  • ROOM_PORT: This is the port number used by the server to listen for incoming connections from clients.

Server

The Server class represents the server-side of the chat application. It has the following methods:

  • startServer: This method starts the server and listens for incoming connections from clients. When a client connects, it creates a new ClientHandler object to handle the client's communication with the server.

SocketHelper

The SocketHelper class provides utility methods for closing resources (sockets, buffered readers, and buffered writers). It has the following method:

  • closeResources: This method closes all resources (socket, buffered reader, and buffered writer) passed to it as arguments.

This markdown file was generated by ChatGPT, a highly advanced artificial intelligence language model designed to assist with generating informative and coherent content.