Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

applets and networking

Posted on 1999-07-30
4
Medium Priority
?
179 Views
Last Modified: 2010-04-16
null
0
Comment
Question by:lmosquera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
gadio earned 600 total points
ID: 1247401
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.*;
import java.net.*;
import java.io.*;

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 ) {
        System.out.println(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");
        System.exit(0);
      }
      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;
      start();
      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 = is.read();
            if( b != -1 )
              os.write(b);
        }
        os.close();
        System.out.println( this+" connection ended.");
      } catch(IOException e) {
      }
  }
}

0
 
LVL 6

Expert Comment

by:gadio
ID: 1247402
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.
0
 

Author Comment

by:lmosquera
ID: 1247403

  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)
and
"Atila"
  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.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1247404
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question