Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package factory;
- import java.io.IOException;
- import java.io.Serializable;
- import java.net.InetAddress;
- import java.net.InetSocketAddress;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.net.SocketAddress;
- import java.rmi.server.RMISocketFactory;
- public class ASIRmiSocketFactory extends RMISocketFactory implements Serializable
- {
- private int timeoutMillis; // timeout conection.
- private String proxy; // ??
- private InetAddress ipVictimaInsie;
- private int portVictimaInside;
- private InetAddress ipVictimaOutside;
- private int portVictimaOutside;
- public ASIRmiSocketFactory() throws IOException
- {
- }
- /**
- * Creates a new instance of ASIRmiSocketFactory, and installs itself as the new default;
- * can only happen once, else an exception is thrown.
- *
- * @param ipVictimaInside The InetAddress of the network interface on which to bind server
- * sockets; if null, will bind to all interfaces.
- */
- public ASIRmiSocketFactory(InetAddress ipVictimaInside, int portVictimaInside, InetAddress ipVictimaOutside, int portVictimOutside, int timeoutMillis) throws IOException
- {
- this.timeoutMillis = timeoutMillis;
- this.ipVictimaInsie = ipVictimaInside;
- this.portVictimaInside = portVictimaInside;
- this.ipVictimaOutside = ipVictimaOutside;
- this.portVictimaOutside = portVictimOutside;
- //RMISocketFactory.setSocketFactory(this);
- }
- /** Implements RMISocketFactory by just creating a normal ServerSocket; same as default impl? */
- @Override
- public ServerSocket createServerSocket(int port) throws IOException
- {
- System.out.println("yee estoy usando la factory de sockets. (server) ");
- ServerSocket ss = new ServerSocket(portVictimaInside, 50, ipVictimaInsie);
- return ss;
- }
- /**
- * Implements RMISocketFactory by creating a Socket, but connecting with a short timeout;
- * 5-sec(may act like 15-sec... see class javadoc) or as defined in the constructor.
- * <p>
- * May replace the given host with a proxy if configured; first the proxies
- * map is checked; if no match there then the default proxy is used if configured;
- * otherwise no host replacement is made.
- */
- @Override
- public Socket createSocket(String host, int port) throws IOException
- {
- // System.out.println("yee estoy usando la factory de sockets. (cliente)");
- // System.out.println("Proxy: "+proxy);
- // System.out.println("Host: "+host);
- // System.out.println("Server: "+ipVictimaInsie);
- // System.out.println("Port: "+port);
- // Replace host with proxy, if defined via lookup map or default proxy...
- // if (proxy != null)
- // {
- // host = proxy;
- // }
- // System.out.println("Host2: "+host);
- Socket s = new Socket();
- SocketAddress sa = new InetSocketAddress(ipVictimaOutside, portVictimaOutside);
- try { s.connect(sa, timeoutMillis); }
- catch (IOException ioe) // timeout
- {
- throw ioe;
- }
- return s;
- }
- /**
- * Optional: Set a default proxy for all calls to createSocket(), replacing any
- * host passed to that call; may be overridden if
- * a proxies Map contains a proxy for the given host.
- * See the javadoc for setProxies() for more background info.
- * <p>
- * This method may be called anytime after construction; subsequent calls
- * overwrite any previous setting. Note that this RMISocketFactory is
- * essentially static in the JVM, so any proxy changes affect all users.
- */
- public void setProxy(String proxy)
- {
- this.proxy = proxy;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement