server program
________________
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.net.*;
import java.io.*;
import java.lang.String.*;
import java.lang.*;

public class softwar
{

public static void main(String[] args)throws Exception
{ int n;
softwar s=new softwar("client",1111);
}
public softwar(String client,int port) throws Exception
{
try{
Socket socket;
ServerSocket serverSocket;
BufferedInputStream bis;
BufferedOutputStream bos;
PrintWriter bot;
BufferedReader bin;
try
{
int in;
serverSocket= new ServerSocket (5000);

System.out.println (" Waiting for client on port 5000");

while(true)
{
socket=serverSocket.accept();
System.out.println( " THE CLIENT"+" "+
socket.getInetAddress() +":"+socket.getPort()+" IS CONNECTED ");

try
{
bin=new BufferedReader(new InputStreamReader(socket.getInputStream()));
bot=new PrintWriter(socket.getOutputStream(),true);
bot.println("from client"+bin.readLine());

byte[] rcv=new byte[8192];
bis=new BufferedInputStream(socket.getInputStream());
bos=new BufferedOutputStream(new FileOutputStream("inservr.txt"));

while((in=bis.read(rcv))!=-1)
{
bos.write(rcv,0,in);
}

}
catch(Exception e){e.printStackTrace();}

}
} catch(Exception e){e.printStackTrace();}
} catch(Exception e){e.printStackTrace();}
}
}

client program
______________
//TCPClient.java
package com.redirect;
import java.io.*;
import java.net.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

class Client
{
protected DataInputStream in;
protected DataOutputStream out;

public static void main(String argv[]) throws Exception
{
String FromServer;
String ToServer;
PrintStream orgStream = null;
PrintStream fileStream = null;
BufferedInputStream bis;
BufferedOutputStream bos;


Socket clientSocket = new Socket("localhost", 5000);
int in1;

try
{
// Saving the orginal stream
orgStream = System.out;
fileStream = new PrintStream(new FileOutputStream("out.txt",true));
// Redirecting console output to file
System.setOut(fileStream);
// Redirecting runtime exceptions to file

try{
String cmd = "reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\"";
//\Microsoft"+"\\Windows\\CurrentVersion\\Uninstall\ "";

// This one will show you software categories installed
//String cmd = "reg query \"HKEY_LOCAL_MACHINE\\Software\"";

Process p = Runtime.getRuntime().exec(cmd);

Thread.sleep(2000l); //terrible, the right way is p.waitFor

//p.waitFor(); /* this command sometimes hangs on windows !!!???*/

InputStream in = p.getInputStream();

byte[] bytes = new byte[16384];

StringBuffer buf = new StringBuffer();

while(true) {
int num = in.read(bytes);

if(num == -1) break;

buf.append(new String(bytes,0,num,"UTF-8"));
}

System.out.println(buf.toString());

System.setOut(fileStream);
p.destroy();

bis=new BufferedInputStream(new FileInputStream("out.txt"));
bos=new BufferedOutputStream(clientSocket.getOutputStream( ));
byte[] byteArray=new byte[8192];
while((in1=bis.read(byteArray))!=-1)
{
bos.write(byteArray,0,in1);
}
bis.close();
bos.close();

}
catch(Exception e)
{
e.printStackTrace();
}
System.setErr(fileStream);
throw new Exception("Test Exception");

}
catch (FileNotFoundException fnfEx)
{
System.out.println("Error in IO Redirection");
fnfEx.printStackTrace();
}
catch (Exception ex)
{
//Gets printed in the file
System.out.println("Redirecting output & exceptions to file");
ex.printStackTrace();
}
finally
{
//Restoring back to console
System.setOut(orgStream);
//Gets printed in the console
System.out.println("Redirecting file output back to console");
}
}
}



error is on server side please help me:confused:

error: Waiting for client on port 5000
THE CLIENT /127.0.0.1:50102 IS CONNECTED
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream. java:129)
at java.io.BufferedInputStream.read1(BufferedInputStr eam.java:256)
at java.io.BufferedInputStream.read(BufferedInputStre am.java:317)
at java.io.FilterInputStream.read(FilterInputStream.j ava:90)
at softwar.<init>(softwar.java:54)
at softwar.main(softwar.java:15)