INTRODUCTION: Chatting has become a daily activity among humans in this modern age. Sending messages and receiving messages through a network or server is called chatting. For assignment, I have created a simple Chat application using java coding as its platform and I have called the chat application as “Fairy Chat Application”. User can use this chat application to chat with their friend for fun or to create a network among them and communicate through the application. For those that have became bored with talking with phone or oral and for those who wanted to communicate in different way. This Fairy Chat Application is an answer for them. The Fairy chat application system presented here consists of two classes: FairyChatServer and ClientWindow. The FairyChatServer class is responsible for accepting connections from clients and providing each client with a 1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
INTRODUCTION:
Chatting has become a daily activity among humans in this modern age. Sending
messages and receiving messages through a network or server is called chatting. For
assignment, I have created a simple Chat application using java coding as its platform
and I have called the chat application as “Fairy Chat Application”. User can use this chat
application to chat with their friend for fun or to create a network among them and
communicate through the application.
For those that have became bored with talking with phone or oral and for those
who wanted to communicate in different way. This Fairy Chat Application is an answer
for them.
The Fairy chat application system presented here consists of two classes:
FairyChatServer and ClientWindow. The FairyChatServer class is responsible for
accepting connections from clients and providing each client with a dedicated thread for
messaging. The ClientWindow is an extension of class Thread. This class is responsible
for receiving client messages and broadcasting those messages to other clients.
1
SOURCE CODE FOR FAIRYCHAT APPLICATION
Listing 1 is source code for FairyChatserver. The source code contains the coding to store the port on which the will listen for new connections. The chat server attempts to create a new server socket and begin to accept connections. First, a new ServerSocket object is created with a specific port. The code then enters an endless loop, continuously accepting connections and creating new chat client . The ServerSocket.accept() method waits forever until a new connection is established. When a new connection is detected, a Socket object is created inherently and returned. A new ClientConnetcion object is then constructed with the newly created socket. Since the ClientConnection is a Thread, we must call the start method to make the chat client code run.
To run the server, the users have to save the source code in java bin as “FairyChatServer.java”. Then the users have to compile in the command prompt.
public class FairyChatServer{ // public FairyChatServer (int port) throws IOException ... // public static void main (String args[]) throws IOException ...
public FairyChatServer () throws IOException { ServerSocket serverSocket = new ServerSocket (2000); // The above statement is the ServerSocket class and its object serverSocket, which// listen's for the port Number.
while (true)
// Here the above statement while loop which is ready to continuously listen for the// client connection.
{ Socket client = serverSocket.accept ();
2
// The above statement get the client's socket.
System.out.println ("Accepted from " + client.getInetAddress ());
// Above statement get the Inet Address of each client.
ClientsConnections cCon = new ClientsConnections (client); cCon.start (); } }
public static void main (String args[]) throws Exception{ new FairyChatServer ();}
}
class ClientsConnections extends Thread{ protected Socket socket; protected DataInputStream dti; protected DataOutputStream dto; static String selFont,selStyle,sendStr; static int selSize;
public ClientsConnections (Socket s) throws IOException { this.socket = s; dti = new DataInputStream (new BufferedInputStream (s.getInputStream ())); dto = new DataOutputStream (new BufferedOutputStream (s.getOutputStream ())); }
protected static Vector clientConnections = new Vector ();
public void run () { try { clientConnections.addElement (this); while (true) { String msg = dti.readUTF (); /* int i,li,starti,startli,end,chs;
Listing 2 is source code to open the chat window for client to chat. The source code contains layout of Login window to log into the chat application such as user name, user password, start button and cancel button in UserFrame( ). Then next part of source code part contains the layout of the chat applet with certain main function to run the application. To run the chat applet the user have to save the source code in java bin as ClientWindow.java. Then user have to compile in command prompt in order to open the chat window applet and start chatting.
Operating System: Windows* 98/Me/2000/XPProcessor: Pentium* III 800 MHz or any affordable processor Memory: 128 MB RAM (256 MB RAM Recommended)Software: 1) j2sdk1.4.2_15 (77.3 MB size) 2) Command prompt 3) Notepad Misc. Hardware: Keyboard and mouse (compatible with PC or laptop)
INSTRUCTION
1. Start Windows* 98/Me/2000/XP.2. Copy FairyChatServer and ClientWindow source code in notepad and save it in
java bin according to the class name .3. Open command prompt and compile FairyChatServer.java4. Then Open a different command prompt an compile ClientWindow.java.5. Once the Chat window open, user may start to chat.
11
Step 1:Save FairyChatServer.java
12
13
Step 2:Save ClientWindow.java
14
15
16
Step 3:Compile FairyChatServer.java in Command prompt
Step 4:Compile ClientWindow.java in Command prompt
Step 5:Key in User name ,Password and server name in login Applet once it appear after compiling ClientWindow.java
17
Step 6:Click the Start button to log in.
Step 7:User may start chat once the Chatwindow appear.
Step 8:To send the text .User may enter the text in text box and click send to send the text to other user and wait for the reply from other user.
18
Step 9:To exit the Chat room, user has to click the close button to exit.
LIMITATION:
Although, Fairy Chat Application is running, it still face some of limitation. This limitation have make the chat application a bit low in performance.Fairy Chat application system limitation are: 1) User can’t change the font colors even though a combo box is given.2) User can’t change the font size even though a combo box is given.3) Users only can chat in main chat room. There is no private room for the user to chat personally.4) There is no icon in the applet.5) The font will not change after the changing it into different font.6) User can’t change the background colors.
RECOMMENDATIONS:
Every limitation can be overcome by a solution. Same goes to the limitation of Fairy Chat application. It can be overcome. In future would I have, to create a better chat application system which will allow users to:
1) Change the Font.
19
2) Change the Font Size3) Change The Font Colors4) Change the background colors5) Send icon6) Send animation icon.7) Send sound effect8) Chat in private room.
CONCLUSION:
After finishing my assignment, I came to know more well about java GUI application. This assignment have given a opportunity to level up my ability and skills in designing simple chat application using java as my platform. After finishing the assignment I gain more ideas to develop the Fairy chat application into a better system after this. The assignment has given me knowledge and understanding about the Java GUI application.