Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1.  
  2. package factory;
  3.  
  4. import java.io.IOException;
  5. import java.io.Serializable;
  6. import java.net.InetAddress;
  7. import java.net.InetSocketAddress;
  8. import java.net.ServerSocket;
  9. import java.net.Socket;
  10. import java.net.SocketAddress;
  11. import java.rmi.server.RMISocketFactory;
  12.  
  13. public class ASIRmiSocketFactory extends RMISocketFactory implements Serializable
  14. {
  15. private int timeoutMillis; // timeout conection.
  16. private String proxy; // ??
  17. private InetAddress ipVictimaInsie;
  18. private int portVictimaInside;
  19. private InetAddress ipVictimaOutside;
  20. private int portVictimaOutside;
  21.  
  22. public ASIRmiSocketFactory() throws IOException
  23. {
  24.  
  25. }
  26.  
  27. /**
  28. * Creates a new instance of ASIRmiSocketFactory, and installs itself as the new default;
  29. * can only happen once, else an exception is thrown.
  30. *
  31. * @param ipVictimaInside The InetAddress of the network interface on which to bind server
  32. * sockets; if null, will bind to all interfaces.
  33. */
  34. public ASIRmiSocketFactory(InetAddress ipVictimaInside, int portVictimaInside, InetAddress ipVictimaOutside, int portVictimOutside, int timeoutMillis) throws IOException
  35. {
  36. this.timeoutMillis = timeoutMillis;
  37. this.ipVictimaInsie = ipVictimaInside;
  38. this.portVictimaInside = portVictimaInside;
  39. this.ipVictimaOutside = ipVictimaOutside;
  40. this.portVictimaOutside = portVictimOutside;
  41. //RMISocketFactory.setSocketFactory(this);
  42. }
  43.  
  44. /** Implements RMISocketFactory by just creating a normal ServerSocket; same as default impl? */
  45. @Override
  46. public ServerSocket createServerSocket(int port) throws IOException
  47. {
  48. System.out.println("yee estoy usando la factory de sockets. (server) ");
  49. ServerSocket ss = new ServerSocket(portVictimaInside, 50, ipVictimaInsie);
  50. return ss;
  51. }
  52.  
  53. /**
  54. * Implements RMISocketFactory by creating a Socket, but connecting with a short timeout;
  55. * 5-sec(may act like 15-sec... see class javadoc) or as defined in the constructor.
  56. * <p>
  57. * May replace the given host with a proxy if configured; first the proxies
  58. * map is checked; if no match there then the default proxy is used if configured;
  59. * otherwise no host replacement is made.
  60. */
  61. @Override
  62. public Socket createSocket(String host, int port) throws IOException
  63. {
  64. // System.out.println("yee estoy usando la factory de sockets. (cliente)");
  65. // System.out.println("Proxy: "+proxy);
  66. // System.out.println("Host: "+host);
  67. // System.out.println("Server: "+ipVictimaInsie);
  68. // System.out.println("Port: "+port);
  69. // Replace host with proxy, if defined via lookup map or default proxy...
  70. // if (proxy != null)
  71. // {
  72. // host = proxy;
  73. // }
  74. // System.out.println("Host2: "+host);
  75. Socket s = new Socket();
  76. SocketAddress sa = new InetSocketAddress(ipVictimaOutside, portVictimaOutside);
  77. try { s.connect(sa, timeoutMillis); }
  78. catch (IOException ioe) // timeout
  79. {
  80. throw ioe;
  81. }
  82. return s;
  83. }
  84.  
  85. /**
  86. * Optional: Set a default proxy for all calls to createSocket(), replacing any
  87. * host passed to that call; may be overridden if
  88. * a proxies Map contains a proxy for the given host.
  89. * See the javadoc for setProxies() for more background info.
  90. * <p>
  91. * This method may be called anytime after construction; subsequent calls
  92. * overwrite any previous setting. Note that this RMISocketFactory is
  93. * essentially static in the JVM, so any proxy changes affect all users.
  94. */
  95. public void setProxy(String proxy)
  96. {
  97. this.proxy = proxy;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement