1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }