SIMPLE CHAT APPLICATION
1.Download this file compile and run and keep the command prompt open.....
This is the server code....
import java.io.*;
import java.net.*;
class VikramServer
{
public static void main (String args[]) throws Exception
{
try
{
String CStr="";
String UStr="";
System.out.println("********************* Server**********************");
ServerSocket SS = new ServerSocket(8888);
Socket OS = SS.accept();
DataInputStream Cinp =new DataInputStream(OS.getInputStream());
DataInputStream Uinp =new DataInputStream(System.in);
PrintStream PS = new PrintStream(OS.getOutputStream());
while(true)
{
CStr=Cinp.readLine();
System.out.println("Client : " +CStr);
if(CStr.equals("exit"))
break;
System.out.print("Server : ");
UStr=Uinp.readLine();
PS.println(UStr);
}
}catch(Exception e){System.err.println(e);};
}
}
import java.io.*;
import java.net.*;
class VikramClient
{
public static void main(String args[]) throws Exception
{
try
{
String Schat="";
String Sstr="";
Socket SC = new Socket("localhost",8888);
DataInputStream Uinp =new DataInputStream(System.in);
DataInputStream Sinp =new DataInputStream(SC.getInputStream());
PrintStream PS = new PrintStream(SC.getOutputStream());
System.out.println("********************* Client**********************");
while(true)
{
System.out.print("Client : ");
Schat=Uinp.readLine();
if(Schat.equals("exit"))
break;
PS.println(Schat);
Sstr=Sinp.readLine();
System.out.println("Server : "+Sstr);
}
}catch(Exception e){System.err.println(e);};
}
}
1.Download this file compile and run and keep the command prompt open.....
This is the server code....
import java.io.*;
import java.net.*;
class VikramServer
{
public static void main (String args[]) throws Exception
{
try
{
String CStr="";
String UStr="";
System.out.println("********************* Server**********************");
ServerSocket SS = new ServerSocket(8888);
Socket OS = SS.accept();
DataInputStream Cinp =new DataInputStream(OS.getInputStream());
DataInputStream Uinp =new DataInputStream(System.in);
PrintStream PS = new PrintStream(OS.getOutputStream());
while(true)
{
CStr=Cinp.readLine();
System.out.println("Client : " +CStr);
if(CStr.equals("exit"))
break;
System.out.print("Server : ");
UStr=Uinp.readLine();
PS.println(UStr);
}
}catch(Exception e){System.err.println(e);};
}
}
2.Download this file compile and run and keep the command prompt open.....
This is the Client code ....import java.io.*;
import java.net.*;
class VikramClient
{
public static void main(String args[]) throws Exception
{
try
{
String Schat="";
String Sstr="";
Socket SC = new Socket("localhost",8888);
DataInputStream Uinp =new DataInputStream(System.in);
DataInputStream Sinp =new DataInputStream(SC.getInputStream());
PrintStream PS = new PrintStream(SC.getOutputStream());
System.out.println("********************* Client**********************");
while(true)
{
System.out.print("Client : ");
Schat=Uinp.readLine();
if(Schat.equals("exit"))
break;
PS.println(Schat);
Sstr=Sinp.readLine();
System.out.println("Server : "+Sstr);
}
}catch(Exception e){System.err.println(e);};
}
}