    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.net;
    019
    020import java.net.DatagramSocket;
    021import java.net.InetAddress;
    022import java.net.SocketException;
    023
    024/**
    025 * The DatagramSocketFactory interface provides a means for the programmer to control the creation of datagram sockets and provide his own DatagramSocket
    026 * implementations for use by all classes derived from {@link org.apache.commons.net.DatagramSocketClient} . This allows you to provide your own DatagramSocket
    027 * implementations and to perform security checks or browser capability requests before creating a DatagramSocket.
    028 */
    029public interface DatagramSocketFactory {
    030
    031    /**
    032     * Creates a DatagramSocket on the local host at the first available port.
    033     *
    034     * @return the socket
    035     * @throws SocketException If the socket could not be created.
    036     */
    037    DatagramSocket createDatagramSocket() throws SocketException;
    038
    039    /**
    040     * Creates a DatagramSocket on the local host at a specified port.
    041     *
    042     * @param port The port to use for the socket.
    043     * @return the socket
    044     * @throws SocketException If the socket could not be created.
    045     */
    046    DatagramSocket createDatagramSocket(int port) throws SocketException;
    047
    048    /**
    049     * Creates a DatagramSocket at the specified address on the local host at a specified port.
    050     *
    051     * @param port  The port to use for the socket.
    052     * @param localAddress The local address to use.
    053     * @return the socket
    054     * @throws SocketException If the socket could not be created.
    055     */
    056    DatagramSocket createDatagramSocket(int port, InetAddress localAddress) throws SocketException;
    057}