Пример #1
0
 /**
  * Creates a datagram socket, bound to the specified local socket address.
  *
  * <p>If, if the address is <code>null</code>, creates an unbound socket.
  *
  * <p>
  *
  * <p>If there is a security manager, its <code>checkListen</code> method is first called with the
  * port from the socket address as its argument to ensure the operation is allowed. This could
  * result in a SecurityException.
  *
  * @param bindaddr local socket address to bind, or <code>null</code> for an unbound socket.
  * @exception SocketException if the socket could not be opened, or the socket could not bind to
  *     the specified local port.
  * @exception SecurityException if a security manager exists and its <code>checkListen</code>
  *     method doesn't allow the operation.
  * @see SecurityManager#checkListen
  * @since 1.4
  */
 public DatagramSocket(SocketAddress bindaddr) throws SocketException {
   // create a datagram socket.
   createImpl();
   if (bindaddr != null) {
     bind(bindaddr);
   }
 }
Пример #2
0
 /**
  * Constructs a datagram socket and binds it to any available port on the local host machine. The
  * socket will be bound to the {@link InetAddress#isAnyLocalAddress wildcard} address, an IP
  * address chosen by the kernel.
  *
  * <p>If there is a security manager, its <code>checkListen</code> method is first called with 0
  * as its argument to ensure the operation is allowed. This could result in a SecurityException.
  *
  * @exception SocketException if the socket could not be opened, or the socket could not bind to
  *     the specified local port.
  * @exception SecurityException if a security manager exists and its <code>checkListen</code>
  *     method doesn't allow the operation.
  * @see SecurityManager#checkListen
  */
 public DatagramSocket() throws SocketException {
   // create a datagram socket.
   createImpl();
   try {
     bind(new InetSocketAddress(0));
   } catch (SocketException se) {
     throw se;
   } catch (IOException e) {
     throw new SocketException(e.getMessage());
   }
 }
Пример #3
0
 /**
  * Get the <code>DatagramSocketImpl</code> attached to this socket, creating it if necessary.
  *
  * @return the <code>DatagramSocketImpl</code> attached to that DatagramSocket
  * @throws SocketException if creation fails.
  * @since 1.4
  */
 DatagramSocketImpl getImpl() throws SocketException {
   if (!created) createImpl();
   return impl;
 }