Client/Server Chat Application


client/server chat Application

Client/Server Chat Application

Client/Server Chat Application is a Chat Application To Communicate one

Node to another node via network. Here, I Show you Client/ Server Chat

Application Using JAVA Language.

How to Use Client/Server Chat Application

Method-1

you can use this Chat Application in one System Also. you open two CMD

Windows. in One cmd window you run the client program and in another

window you run the server program. and Enjoy the chat with each others.

Method-2.

you can run this program in two System also.for that first you establish a

network between these two computer via network cable, adhoc approach

or any other method. Now you run the client program in one system and

run the server program in another system and enjoy the chat application.

MyClient1.java


import java.io.*;
import java.net.*;

public class MyClient1
{
Socket s;
DataInputStream din;
DataOutputStream dout;

public MyClient1()
{
try
{
s=new Socket("localhost",10);
//Socket("192.168.1.93",8);
System.out.println(s);
din=new DataInputStream(s.getInputStream());
dout=new DataOutputStream(s.getOutputStream());
clientChat();
}
catch(Exception e)
{
System.out.println(e);
}
}

public void clientChat() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s1;

do
{
s1=br.readLine();
dout.writeUTF(s1);
dout.flush();
System.out.println("Server Message : " +din.readUTF());
}
while(!s1.equals("stop"));
}
public static void main(String s[])
{
new MyClient1();
}
}


MyServer1.java

import java.io.*;
import java.net.*;

public class MyServer1
{
ServerSocket ss;
Socket s;
DataInputStream dis;
DataOutputStream dos;

public MyServer1()
{
try
{
System.out.println("Server Started :");
ss=new ServerSocket(10);
s=ss.accept();
System.out.println(s);
System.out.println("Client Connected :");
dis=new DataInputStream(s.getInputStream());
dos=new DataOutputStream(s.getOutputStream());
serverChat();
}
catch(Exception e)
{
System.out.println(e);
}
}

public static void main(String s[])
{
new MyServer1();
}

public void serverChat() throws IOException
{
String str,s1;
do
{
str=dis.readUTF();
System.out.println("Client Message : "+str);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s1=br.readLine();
dos.writeUTF(s1);
dos.flush();
}
while(!s1.equals("stop"));
}
}


How To run Client/server chat Application

To run Client/Server chat server you Follow the below steps..

Step-1. First you copy the MyClient1.java program , Paste in Notepad and

Save it as MyClient1.java

Step-2. Now, you Copy the MyServer1.java program in the same directory

and Paste in Notepad and Save it as MyServer1.java

Step-3. Now, In one CMD window , First you Compile MyServer1.java

Program so that you will get the MyServer1.class File. this cmd windows

will works as a server for your chat application.

Step-4. In Another CMD windows  , you Compile MyClient1.java

Program. it will works as the Client for your chat Application.

Step-5. Now, you run the MyServer1 program. it will wait for the

connection from the client program.

Step-6. Now, you run the MyClient1 program. when it will successfully

connect with your MyServer1 Program , you can start your chat.

MyServer1 Screenshots


MyClient1 Screenshots

client/server chat Application



Thank You To All My Reader
Deepak Gupta
www.i-world-tech.blogspot.in

Related Post

1. Layout Manager in JAVA

2. How we Install Apache Tomcat Server

3. How To Install JDK on Windows

4. JDK 8

5. Content Management System ( CMS )

6. JavaScript Form Validation

7. JavaScript Operator

8. HTML Marquee Tag

9. How To Add Music File To Website

10. How We Enable JavaScript in Browser

Comments

  1. Great stuff,Great site, Thanks for sharing information. I really liked it .

    ReplyDelete

Post a Comment