Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/11/2010, 12:00
liev13
 
Fecha de Ingreso: noviembre-2010
Mensajes: 15
Antigüedad: 13 años, 5 meses
Puntos: 0
Pregunta servidor proxy en java!!!

Hola que tal, quisiera recibir algo de ayuda estoy programando un servidor proxy en java, y encontre un codigo para apollarme el problema surge que no se como comprobar que e proxy esta funcionando porque en el navegador(firefox) le pongo que use proxy LOCALHOST con puerto 80, pero a la hora de realizar peticiones aparentemente el programa trabaja pero no se queda con las paginas, ni en disco ni en ninguna memo temporal...

soy principiante con este tipo de cosas asi que les dejo el codigo que tengo por si alguien me puede ayudar, gracias y si me pueden explicar como realizar la configuracion del firefox para que use el proxy correctamente se los agradeceria muchisimo porque pienso qeu talvez tenga error ahi, bueno gracias por leer y por tu valioso tiempo...

CLASE MAIN:

package proxyserver;

/**
*
* @author Liev
*/

import com.sun.corba.se.spi.activation.Server;
import java.net.* ;
import java.io.* ;
import java.lang.* ;
import java.util.* ;



/**
*
* @author user
*/
public class Main {

/**
* @param args the command line arguments
*/
// Variable to track if an error occurred
boolean errorOccurred = false;

//Variables for the host and port parameters


public static void main(String[] args) {
// TODO code application logic here

int localPort = -1;
int remotePort = -1;
String remoteHost = "localhost";

System.out.print("LA APLICACION HA INICIADO A CORRER!!!!!");


Integer parseLocalPort = new Integer(555);
System.out.println("EL PUERTO LOCAL ES 555");
Integer parseRemotePort = new Integer(80);
System.out.println("EL PUESRTO REMOTO ES 80");
localPort =555 ;
//ERROR? COMO PUEDE SER EL MISMO PUERTO LOCAL Y REMOTO? LOCALHOST?
remotePort = 80;

//Create a listening socket at proxy

ServerSocket server = null;
try
{
server = new ServerSocket(localPort);
}

catch(IOException e)
{
System.err.println("Error: " + e.getMessage());
System.exit(-1);
}

//Loop to listen for incoming connection,
//and accept if there is one

Socket incoming = null;
Socket outgoing = null;

while(true)
{
try
{
// Create the 2 sockets to transmit incoming
// and outgoing traffic of proxy server
incoming = server.accept();
outgoing = new Socket(remoteHost, remotePort);

// Create the 2 threads for the incoming
// and outgoing traffic of proxy server
ProxyThread thread1 = new ProxyThread(incoming, outgoing);
thread1.start();

ProxyThread thread2 = new ProxyThread(outgoing, incoming);
thread2.start();
}
catch (UnknownHostException e)
{
System.err.println("Error: Unknown Host " + remoteHost);
System.exit(-1);
}
catch(IOException e)
{
//continue
System.exit(-2);
}
}
}

}

CLASE PROXYSERVER
package proxyserver;

/**
*
* @author user
*/
import java.net.* ;
import java.io.* ;
import java.lang.* ;
import java.util.* ;

class ProxyThread extends Thread
{
Socket incoming, outgoing;

ProxyThread(Socket in, Socket out)
{
incoming = in;
outgoing = out;
}

// Overwritten run() method of thread,
// does the data transfers
public void run()
{
byte[] buffer = new byte[5000];
int numberRead = 0;
OutputStream toClient;
InputStream fromClient;

try{
toClient = outgoing.getOutputStream();
fromClient = incoming.getInputStream();

while(true)
{
numberRead = fromClient.read(buffer, 0, 50);
if(numberRead == -1)
{
incoming.close();
outgoing.close();
}
String st = new String(buffer,"US-ASCII");
System.out.println("\n\nXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXX\n\nXXXXXXXXXXXXXXXX\n\n" + st);


toClient.write(buffer, 0, numberRead);
}
}
catch(IOException e)
{
}
catch(ArrayIndexOutOfBoundsException e)
{
}
}
}

ESPERO SU PRONTA RESPUESTA COMPAÑEROS