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