Add to Favorites    Make Home Page 10715 Online  
 Language Categories  
 Our Services  

Home » Java Home » Networking Home » Server Client project to get PC health of remote sever (Mini Project)


Search Projects & Source Codes:

Title Server Client project to get PC health of remote sever (Mini Project)
Author Sumit Agarwal
Author Email sumit.agarwal [at]
Description I have created a socket4444 on a PC which I treat as a server.
Now using my PC I am firing all system and DOS commands on the server and getting response of same on my PC.
Category Java » Networking
Hits 389730
Code Select and Copy the Code
// To be run at server side and will act as a server // import*; import*; public class MainServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(4445); } catch (IOException e) { System.err.println("Could not listen on port: 4445."); System.exit(1); } Socket clientSocket = null; try { clientSocket = serverSocket.accept(); } catch (IOException e) { System.err.println("Accept failed."); System.exit(1); } PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),true); BufferedReader in = new BufferedReader( new InputStreamReader( clientSocket.getInputStream())); String inputLine, outputLine; MainProtocol kkp = new MainProtocol(); // outputLine = kkp.processInput(null); // out.println(outputLine); while ((inputLine = in.readLine()) != null) { if (inputLine.equals("bye")) break; outputLine = kkp.processInput(inputLine); out.println(outputLine); outputLine = null; } out.close(); in.close(); clientSocket.close(); serverSocket.close(); } } // Server side component used to execute commands and returning result // import java.lang.*; import*; public class MainProtocol { String sa,sb; // String sb,sa; public String processInput(String args) { try { sb = new String(); sa = new String(); Runtime rt=Runtime.getRuntime(); Process p=rt.exec("cmd /c "+ args); InputStream is = p.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); while ((sb = br.readLine()) != null) { sa += sb ; // sa +=" "; } p.waitFor(); System.out.println("process "+p.exitValue()); } catch(Exception e) { System.out.println(e.getMessage()+ "sumit"); } return sa ; } } // Client side component. Commands are to fired from here only // import*; import*; public class MainClient { public static void main(String[] args) throws IOException { Socket kkSocket = null; PrintWriter out = null; BufferedReader in = null; try { kkSocket = new Socket("", 4445); out = new PrintWriter(kkSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Exception " + e); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection."); System.exit(1); } BufferedReader stdIn = new BufferedReader(new InputStreamReader(; String fromServer; String fromUser; while ((fromUser = stdIn.readLine()) != "hi") { // System.out.println("Server: " + fromServer); // if (fromServer.equals("Bye.")) // break; // fromUser = stdIn.readLine(); if (fromUser != null) { // System.out.println("Client: " + fromUser); out.println(fromUser); fromServer = in.readLine(); System.out.println("Server Response: "+ fromServer); fromServer = null; if (fromUser.equals("bye")) break; } } out.close(); in.close(); stdIn.close(); kkSocket.close(); } }

Related Source Codes

Script Name Author
Sending mail Using JavaMail to Yahoo and Gmail accounts sai prasad
Simple Program in Java to Implement Multithreading Satish.K
Simple Calculator in Java Using Remote Method Invocation Satish.K
Guest Book Application Using Servlets Satish.K
String Manipulation Using Stringification Satish.K
String Manipulation Using Stringification Satish.K
Moving Ball Application Using Java Beans Satish.K
Rapid Roll game subrahmanyeswararao
student mgm arpan
Sourav Datta
Download Manager Sagar
Address Book in Java Rahul Chouhan
address book using java database connectivity(jdbc-msaccess) shekhar bansal
sun Steganography B.Rajavel
Connecting Java with MS-Access - Inserting data in Aseem


Google Groups Subscribe to SourceCodesWorld - Techies Talk

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!

ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page


Google Search


Source Codes is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024, All Rights Reserved.
Page URL:

Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review