Server Socket
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
/**
*
* @author NAVJYOTI
*/
public class echo {
public static void main(String args[])
{
Socket s=null;
BufferedReader bin=null;
BufferedReader cin=null;
PrintWriter pw=null;
String str;
try
{
s=new Socket("127.0.0.1",111);
bin=new BufferedReader(new InputStreamReader(System.in));
cin=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
do
{
System.out.println("enter msg");
str=bin.readLine();
pw.println(str);
pw.flush();
str=cin.readLine();
System.out.println("msg recieved"+str);
}
while(!(str.equalsIgnoreCase("bye")));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
/**
*
* @author NAVJYOTI
*/
public class Rmi {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ServerSocket ss=null;
Socket s=null;
BufferedReader bin=null;
BufferedReader cin=null;
PrintWriter pw=null;
String str;
try
{
ss=new ServerSocket(111);
System.out.println("Start!!!");
while(true)
{
s=ss.accept();
System.out.println("CLient Accept"+s);
bin=new BufferedReader(new InputStreamReader(System.in));
cin=new BufferedReader(new InputStreamReader(s.getInputStream()));
pw=new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
do
{
str=cin.readLine();
System.out.println("Received"+str);
System.out.println("enter msg");
str=bin.readLine();
pw.println(str);
pw.flush();
}
while(!(str.equalsIgnoreCase("bye")));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}