Programming Assignment Unit 7
Programming Assignment Unit 7
Server Implementation
ChatServer.java
Code:
import java.io.*;
import java.net.*;
import java.util.*;
String message;
while ((message = in.readLine()) != null) {
System.out.println(userId + ": " + message);
ChatServer.broadcastMessage(userId + ": " + message, this);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
ChatServer.removeClient(this);
System.out.println(userId + " disconnected.");
}
}
Client Implementation
ChatClient.java
Code:
import java.io.*;
import java.net.*;
import java.util.Scanner;
README
README.md
# Online Chat Application
## Overview
This is a simple online chat application developed in Java using socket programming. It allows
multiple users to connect to a central server, send messages, and receive messages from other
users.
## Requirements
- Java Development Kit (JDK) 8 or higher
## How to Run
### Server
1. Compile the server code
2. Run the server
### Client
1. Compile the client code
2. Run the client
## Features
- Server can handle multiple client connections.
- Each client is assigned a unique user ID.
- Clients can send and receive messages in real-time.
## Screenshot
## Notes
- The server runs on port 12345 by default. Ensure this port is available on your machine.
- To change the server address or port for the client, modify the `SERVER_ADDRESS` and
`SERVER_PORT` constants in `ChatClient.java`.