View Javadoc

    1   /*
    2    * Copyright 2001-2005 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
    18  import java.net.DatagramSocket;
    19  import java.net.InetAddress;
    20  import java.net.SocketException;
    21
    22  /****
    23   * DefaultDatagramSocketFactory implements the DatagramSocketFactory
    24   * interface by simply wrapping the java.net.DatagramSocket
    25   * constructors.  It is the default DatagramSocketFactory used by
    26   * {@link org.apache.commons.net.DatagramSocketClient}
    27   *  implementations.
    28   * <p>
    29   * <p>
    30   * @author Daniel F. Savarese
    31   * @see DatagramSocketFactory
    32   * @see DatagramSocketClient
    33   * @see DatagramSocketClient#setDatagramSocketFactory
    34   ***/
    35
    36  public class DefaultDatagramSocketFactory implements DatagramSocketFactory
    37  {
    38
    39      /****
    40       * Creates a DatagramSocket on the local host at the first available port.
    41       * <p>
    42       * @exception SocketException If the socket could not be created.
    43       ***/
    44      public DatagramSocket createDatagramSocket() throws SocketException
    45      {
    46          return new DatagramSocket();
    47      }
    48
    49      /****
    50       * Creates a DatagramSocket on the local host at a specified port.
    51       * <p>
    52       * @param port The port to use for the socket.
    53       * @exception SocketException If the socket could not be created.
    54       ***/
    55      public DatagramSocket createDatagramSocket(int port) throws SocketException
    56      {
    57          return new DatagramSocket(port);
    58      }
    59
    60      /****
    61       * Creates a DatagramSocket at the specified address on the local host
    62       * at a specified port.
    63       * <p>
    64       * @param port The port to use for the socket.
    65       * @param laddr  The local address to use.
    66       * @exception SocketException If the socket could not be created.
    67       ***/
    68      public DatagramSocket createDatagramSocket(int port, InetAddress laddr)
    69      throws SocketException
    70      {
    71          return new DatagramSocket(port, laddr);
    72      }
    73  }