Program to use Remote Server and Client programs to run any application
Program for Server:
import java.io.*;
import java.net.*;
import java.util.*;
class rms
{
public static void main(String ar[]) throws Exception
{
String csent,ssent;
ServerSocket ss=new ServerSocket(1234);
Socket soc=ss.accept();
BufferedReader ifs=new BufferedReader(new InputStreamReader(System.in));
BufferedReader ifc=new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataOutputStream otc=new DataOutputStream(soc.getOutputStream());
csent=ifc.readLine();
Runtime h=Runtime.getRuntime();
Process p=h.exec(csent+'\n');
System.out.println("Executed successfully");
}
}
Program for Client:
import java.io.*;
import java.net.*;
import java.util.*;
class rmc
{
public static void main(String ar[]) throws Exception
{
String csent,ssent;
Socket soc=new Socket("localhost",1234);
BufferedReader ifc=new BufferedReader(new InputStreamReader(System.in));
BufferedReader ifs=new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataOutputStream ots=new DataOutputStream(soc.getOutputStream());
System.out.println("Enter the command to be executed");
csent=ifc.readLine();
ots.writeBytes(csent+'\n');
ssent=ifs.readLine();
System.out.println("The command executed successfully");
}
}
Output for client and server:
Program for Server:
import java.io.*;
import java.net.*;
import java.util.*;
class rms
{
public static void main(String ar[]) throws Exception
{
String csent,ssent;
ServerSocket ss=new ServerSocket(1234);
Socket soc=ss.accept();
BufferedReader ifs=new BufferedReader(new InputStreamReader(System.in));
BufferedReader ifc=new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataOutputStream otc=new DataOutputStream(soc.getOutputStream());
csent=ifc.readLine();
Runtime h=Runtime.getRuntime();
Process p=h.exec(csent+'\n');
System.out.println("Executed successfully");
}
}
Program for Client:
import java.io.*;
import java.net.*;
import java.util.*;
class rmc
{
public static void main(String ar[]) throws Exception
{
String csent,ssent;
Socket soc=new Socket("localhost",1234);
BufferedReader ifc=new BufferedReader(new InputStreamReader(System.in));
BufferedReader ifs=new BufferedReader(new InputStreamReader(soc.getInputStream()));
DataOutputStream ots=new DataOutputStream(soc.getOutputStream());
System.out.println("Enter the command to be executed");
csent=ifc.readLine();
ots.writeBytes(csent+'\n');
ssent=ifs.readLine();
System.out.println("The command executed successfully");
}
}
Output for client and server:
0 comments:
Post a Comment