1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.net;
  17. import java.io.IOException;
  18. import java.net.InetAddress;
  19. import java.net.ServerSocket;
  20. import java.net.Socket;
  21. import java.net.UnknownHostException;
  22. /***
  23. * The SocketFactory interface provides a means for the programmer to
  24. * control the creation of sockets and provide his own Socket
  25. * implementations for use by all classes derived from
  26. * <a href="org.apache.commons.net.SocketClient.html"> SocketClient </a>.
  27. * This allows you to provide your own Socket implementations and
  28. * to perform security checks or browser capability requests before
  29. * creating a Socket.
  30. * <p>
  31. * <p>
  32. * @author Daniel F. Savarese
  33. * @see DefaultSocketFactory
  34. ***/
  35. public interface SocketFactory
  36. {
  37. /***
  38. * Creates a Socket connected to the given host and port.
  39. * <p>
  40. * @param host The hostname to connect to.
  41. * @param port The port to connect to.
  42. * @return A Socket connected to the given host and port.
  43. * @exception UnknownHostException If the hostname cannot be resolved.
  44. * @exception IOException If an I/O error occurs while creating the Socket.
  45. ***/
  46. public Socket createSocket(String host, int port)
  47. throws UnknownHostException, IOException;
  48. /***
  49. * Creates a Socket connected to the given host and port.
  50. * <p>
  51. * @param address The address of the host to connect to.
  52. * @param port The port to connect to.
  53. * @return A Socket connected to the given host and port.
  54. * @exception IOException If an I/O error occurs while creating the Socket.
  55. ***/
  56. public Socket createSocket(InetAddress address, int port)
  57. throws IOException;
  58. /***
  59. * Creates a Socket connected to the given host and port and
  60. * originating from the specified local address and port.
  61. * <p>
  62. * @param host The hostname to connect to.
  63. * @param port The port to connect to.
  64. * @param localAddr The local address to use.
  65. * @param localPort The local port to use.
  66. * @return A Socket connected to the given host and port.
  67. * @exception UnknownHostException If the hostname cannot be resolved.
  68. * @exception IOException If an I/O error occurs while creating the Socket.
  69. ***/
  70. public Socket createSocket(String host, int port, InetAddress localAddr,
  71. int localPort)
  72. throws UnknownHostException, IOException;
  73. /***
  74. * Creates a Socket connected to the given host and port and
  75. * originating from the specified local address and port.
  76. * <p>
  77. * @param address The address of the host to connect to.
  78. * @param port The port to connect to.
  79. * @param localAddr The local address to use.
  80. * @param localPort The local port to use.
  81. * @return A Socket connected to the given host and port.
  82. * @exception IOException If an I/O error occurs while creating the Socket.
  83. ***/
  84. public Socket createSocket(InetAddress address, int port,
  85. InetAddress localAddr, int localPort)
  86. throws IOException;
  87. /***
  88. * Creates a ServerSocket bound to a specified port. A port
  89. * of 0 will create the ServerSocket on a system-determined free port.
  90. * <p>
  91. * @param port The port on which to listen, or 0 to use any free port.
  92. * @return A ServerSocket that will listen on a specified port.
  93. * @exception IOException If an I/O error occurs while creating
  94. * the ServerSocket.
  95. ***/
  96. public ServerSocket createServerSocket(int port) throws IOException;
  97. /***
  98. * Creates a ServerSocket bound to a specified port with a given
  99. * maximum queue length for incoming connections. A port of 0 will
  100. * create the ServerSocket on a system-determined free port.
  101. * <p>
  102. * @param port The port on which to listen, or 0 to use any free port.
  103. * @param backlog The maximum length of the queue for incoming connections.
  104. * @return A ServerSocket that will listen on a specified port.
  105. * @exception IOException If an I/O error occurs while creating
  106. * the ServerSocket.
  107. ***/
  108. public ServerSocket createServerSocket(int port, int backlog)
  109. throws IOException;
  110. /***
  111. * Creates a ServerSocket bound to a specified port on a given local
  112. * address with a given maximum queue length for incoming connections.
  113. * A port of 0 will
  114. * create the ServerSocket on a system-determined free port.
  115. * <p>
  116. * @param port The port on which to listen, or 0 to use any free port.
  117. * @param backlog The maximum length of the queue for incoming connections.
  118. * @param bindAddr The local address to which the ServerSocket should bind.
  119. * @return A ServerSocket that will listen on a specified port.
  120. * @exception IOException If an I/O error occurs while creating
  121. * the ServerSocket.
  122. ***/
  123. public ServerSocket createServerSocket(int port, int backlog,
  124. InetAddress bindAddr)
  125. throws IOException;
  126. }