001    /*
002     * Copyright 2001-2005 The Apache Software Foundation
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.apache.commons.net;
017    
018    import java.net.DatagramSocket;
019    import java.net.InetAddress;
020    import java.net.SocketException;
021    
022    /***
023     * DefaultDatagramSocketFactory implements the DatagramSocketFactory
024     * interface by simply wrapping the java.net.DatagramSocket
025     * constructors.  It is the default DatagramSocketFactory used by
026     * {@link org.apache.commons.net.DatagramSocketClient}
027     *  implementations.
028     * <p>
029     * <p>
030     * @author Daniel F. Savarese
031     * @see DatagramSocketFactory
032     * @see DatagramSocketClient
033     * @see DatagramSocketClient#setDatagramSocketFactory
034     ***/
035    
036    public class DefaultDatagramSocketFactory implements DatagramSocketFactory
037    {
038    
039        /***
040         * Creates a DatagramSocket on the local host at the first available port.
041         * <p>
042         * @exception SocketException If the socket could not be created.
043         ***/
044        public DatagramSocket createDatagramSocket() throws SocketException
045        {
046            return new DatagramSocket();
047        }
048    
049        /***
050         * Creates a DatagramSocket on the local host at a specified port.
051         * <p>
052         * @param port The port to use for the socket.
053         * @exception SocketException If the socket could not be created.
054         ***/
055        public DatagramSocket createDatagramSocket(int port) throws SocketException
056        {
057            return new DatagramSocket(port);
058        }
059    
060        /***
061         * Creates a DatagramSocket at the specified address on the local host
062         * at a specified port.
063         * <p>
064         * @param port The port to use for the socket.
065         * @param laddr  The local address to use.
066         * @exception SocketException If the socket could not be created.
067         ***/
068        public DatagramSocket createDatagramSocket(int port, InetAddress laddr)
069        throws SocketException
070        {
071            return new DatagramSocket(port, laddr);
072        }
073    }