applets and networking

Who is Participating?
gadioConnect With a Mentor Commented:
If you want to redirect IP try out this code. You need yo write
java ip_router 8080 atila 80

 * Program: ip_router. Written by gadio.
 * This program opens a window for each connection to a the port
 * that it bridges. The window have one area for the input and one
 * for the output. Once the communication in finished a close button
 * is enabled.

import java.awt.*;

public class ip_router {
  public ip_router (int origport, String ip, int newport ) {
      try {
        ServerSocket srvs = new ServerSocket( newport );
        while(true) {
            Socket inconnect = srvs.accept();
            Socket bridge = new Socket(ip,origport);
            ip_routerObj so = new ip_routerObj( inconnect, bridge );
      } catch( IOException e ) {

  public static void main(String args[]) {
      if( args.length != 3 ) {
        System.out.println( "Usage:\n java ip_router dest_ip dest_port original_port_on_this_machine\n\n");
      ip_router snoopy = new ip_router(Integer.parseInt(args[1]), args[0], Integer.parseInt(args[2]));

class ip_routerObj {
  private Thread inMonitor, outMonitor;
  Socket inconnect;
  Socket bridge;
  ip_connection con1, con2;
  public ip_routerObj( Socket incon, Socket brdg ) {
      inconnect = incon;
      bridge = brdg;
      String time = (new java.util.Date(System.currentTimeMillis())).toString();
      con1 = new ip_connection( incon, bridge );
      con2 = new ip_connection( bridge, incon );

class ip_connection extends Thread {
  Socket from, to;
  public ip_connection( Socket from_s, Socket to_s ) {
      from = from_s;
      to = to_s;
      System.out.println( this+" starting connection.");
  public void run() {
      try {
        InputStream is = from.getInputStream();
        OutputStream os = to.getOutputStream();
        int b = 0;
        while(b!=-1) {
            b =;
            if( b != -1 )
        System.out.println( this+" connection ended.");
      } catch(IOException e) {

Sorry about the indentation.
This program rerouts ip. I have another version that also opens a window and shows you the communication over the line (the comment is still in). If you want it let me know.
Hope that helps.
lmosqueraAuthor Commented:

  I think I didn't make myself clear enough. Your suggested program seems to redirect from a port in the localhost to a port in a remote host. My situation is the other way around: I have two computers:
"MyComputer"  (with my running thread)
  The user at "My computer" starts the Netscape navigator and typewrites "http://Atila/index.html". The Netscape performs automatically a request to "Atila" for the document "index.html".
BUT, what I would want, is that my thread at "MyComputer" would "catch" or "intercept" this request ("Atila" would not realize anything up to now, neither the user) and performs its own request to "Atila" (or redirects it to some other). In few words, my running thread is acting like a proxy server installed in my local computer "MyComputer", but, transparently to the user (without the user configuring Netscape to use a proxy server in "loopback:some_port".
  Could I trap the browser requests somehow, maybe interacting with it from an applet (given I have all security restrictions disabled)?
 OK, maybe I am demanding too much.
If you have any other suggestion it will be wellcomed, if not I'll give you the points after all.
Thanks for your time.
Well, if you want to 'catch' the users request without him knowing that, you ban do that only by writting some low level native code on the machine that the browser is running on. No way to do that through an applet. Note also that putting the URL in the url testbox is somthing that no applet has control or knowldge about.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.