I have designed a Tunneling Proxy server in java. I have opened an InputStream and OutputStream for a socket. After writing to the socket using the OutputStream, i'm closing only the output stream.
Code:
//ProxyConnection class
try {
toServer = new Socket(host,port);
Proxy.display("open connection to:"+toServer+"(timeout="+timeout+" ms)");
clientIn = fromClient.getInputStream();
clientOut = new BufferedOutputStream(fromClient.getOutputStream());
serverIn = toServer.getInputStream();
serverOut = new BufferedOutputStream(toServer.getOutputStream());
URL u=new URL("anyurl");
BufferedReader in=new BufferedReader(new InputStreamReader(u.openStream()));
String str;
while((str=in.readLine())!=null)
{
clientOut.write(str.getBytes());
Proxy.println(str);
}
clientOut.close();
while(r0!=0 || r1!=0 || (time1-time0)<=timeout)
{
Proxy.println("r0= "+r0+"r1= "+r1);
while((r0=clientIn.available())>0) //This is where I get the error
{
-------
}
I get the following error, when I try to use the InputStream for the same socket.
Code:
java.io.IOException: Stream closed.
at java.net.PlainSocketImpl.available(Unknown Source)
at java.net.SocketInputStream.available(Unknown Source)
at ProxyConnection.run(Proxy.java:131)
at Proxy.run(Proxy.java:249)
at Proxy.main(Proxy.java:284)
Is there anyway I can use the InputStream of that socket?