dcsimg
Hello guys am in a trouble ,proxy program not work well
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   raihan_tharayil
Posted On:   Saturday, September 19, 2009 02:05 PM

last two weeks i am trying to write a proxy program, that is apart of my academic project but the program is not working properly ,the method i used is change my browsers proxy and port no: to localhost:1234 and run my program on 1234 port,it caches all the requests coming through the browser and redirect in to the Internet ,and then i send the data got from Internet to the browser ,but it shows problems, no images are shown here is the code , please help me import java.io.FileInputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.*; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.IOException;   More>>

last two weeks i am trying to write a proxy program, that is apart of my academic project but the program is not working properly ,the method i used is change my browsers proxy and port no: to localhost:1234 and run my program on 1234 port,it caches all the requests coming through the browser and redirect in to the Internet ,and then i send the data got from Internet to the browser ,but it shows problems, no images are shown


here is the code , please help me


			



import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

//import jpcap.JpcapCaptor;


public class Server1 {

private static String http;

public static void main(String[] args) {

ServerSocket ser=null;

Socket Clientsoc=null;
Socket ISPsoc=null;


InputStream Clientsocin=null;
OutputStream Clientsocout=null;
InputStream ISPsocin=null;
OutputStream ISPsocout=null;

FileInputStream fin=null;

String Inip="localhost";
String Outip="192.168.0.102";

int Inport=2000;
int Outport=1234;

int l=0;
String str=null;
String str1=null,str3=null;

StringTokenizer st1=null,st2=null;

byte b[]=new byte[1024];
while(true){

try{

ser =new ServerSocket(Outport);
System.out.println("Sever connected");

//while(true){

Clientsoc = ser.accept();
Clientsocin = Clientsoc.getInputStream();
Clientsocout =Clientsoc.getOutputStream();

//ISPsoc=new Socket(Outip,Inport);
//ISPsocin=ISPsoc.getInputStream();
//ISPsocout=ISPsoc.getOutputStream();



l=Clientsocin.read(b);

System.out.println(l);

str=new String(b,0,l);

}
catch(Exception e){
System.out.println(e);
}




System.out.println(str);
str3=str.substring(str.indexOf("GET")+4,str.indexOf("HTTP")-1);
System.out.println(str3);

if(!str3.equals("http://www.orkut.com/"))
{

try{
// fin = new FileInputStream("/home/dotpoint/NetBeansProjects/netmonit/src/netmonit/Google.html");
BufferedReader in = null;
try {
URL url = new URL(str3);
in = new BufferedReader(new InputStreamReader(url.openStream()));
String st;
StringBuffer page = new StringBuffer();
while ((st = in.readLine()) != null) {
page.append(st + "
");

System.out.println(st);//page.toString()
Clientsocout.write(st.getBytes());
//System.out.println("hai");
}
in.close();
} catch (IOException ex) {
//Logger.getLogger(URLrequest.class.getName()).log(Level.SEVERE, null, ex);
}
// And now 'page' contains the webpage...
finally {
try {
in.close();
} catch (IOException ex) {
// Logger.getLogger(URLrequest.class.getName()).log(Level.SEVERE, null, ex);
}
}
// fin.read(b);
//str1=new String(b,0,1023);

}catch (Exception e)
{
System.out.println("erro"+e);
}


}
else
{
try{

str1="

Not working

";
Clientsocout.write(str1.getBytes());
System.out.println("hai");

}catch(Exception e){
System.out.println(""+e);
}

}



try{
Clientsocin.close();
Clientsocout.close();
ser.close();
}catch(IOException e)
{
System.out.println("io");
}
}

}

}

   <<Less
About | Sitemap | Contact