This is a basic implementation of a client-server chat application in Java. The application allows multiple clients to connect to a server and exchange messages in a chat-like interface.
Client.java
: Contains the implementation of the chat client.Server.java
: Contains the implementation of the chat server.
-
Open a terminal and navigate to the directory containing
Server.java
. -
Compile the server code using the following command:
javac Server.java
-
Run the server using the following command:
java Server
The server will start, and it will listen for incoming connections on port 9999.
Client
-
Open a new terminal window and navigate to the directory containing Client.java.
-
Compile the client code using the following command:
javac Client.java
-
Run the client using the following command:
java Client
The client will connect to the server at 127.0.0.1:9999. You can run multiple instances of the client to simulate multiple users in the chat.
Usage
-Once the client is running, it will prompt you to enter a nickname. -You can send messages to the chat by typing them in the terminal and pressing Enter. -To change your nickname, type /nick newnickname and press Enter. -To quit the chat, type /q and press Enter.
Important Notes
-Ensure that you have Java installed on your system. -The server and client must be run on the same machine. -Adjust firewall settings if necessary to allow connections on port 9999.