Package java.net

Class PlainDatagramSocketImpl

    • Constructor Detail

      • PlainDatagramSocketImpl

        public PlainDatagramSocketImpl​(FileDescriptor fd,
                                       int localPort)
      • PlainDatagramSocketImpl

        public PlainDatagramSocketImpl()
    • Method Detail

      • bind

        public void bind​(int port,
                         InetAddress address)
                  throws SocketException
        Description copied from class: DatagramSocketImpl
        Binds the datagram socket to the given local host/port. Sockets must be bound prior to attempting to send or receive data.
        Specified by:
        bind in class DatagramSocketImpl
        Parameters:
        port - the port on the local host to bind to.
        address - the address on the multihomed local host to bind to.
        Throws:
        SocketException - if an error occurs while binding, for example, if the port has been already bound.
      • finalize

        protected void finalize()
                         throws Throwable
        Description copied from class: Object
        Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

        Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

        If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

        Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

        Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

        Overrides:
        finalize in class Object
        Throws:
        Throwable
      • getOption

        public Object getOption​(int option)
                         throws SocketException
        Description copied from interface: SocketOptions
        Gets the value for the specified socket option.
        Parameters:
        option - the option identifier.
        Returns:
        the option value.
        Throws:
        SocketException - if an error occurs reading the option value.
      • getTimeToLive

        public int getTimeToLive()
                          throws IOException
        Description copied from class: DatagramSocketImpl
        Gets the time-to-live (TTL) for multicast packets sent on this socket. The TTL option defines how many routers a packet may be pass before it is discarded.
        Specified by:
        getTimeToLive in class DatagramSocketImpl
        Returns:
        the time-to-live option as an integer value.
        Throws:
        IOException - if an error occurs while getting the time-to-live option value.
      • join

        public void join​(InetAddress addr)
                  throws IOException
        Description copied from class: DatagramSocketImpl
        Adds this socket to the multicast group addr. A socket must join a group before being able to receive data. Further, a socket may be a member of multiple groups but may join any group only once.
        Specified by:
        join in class DatagramSocketImpl
        Parameters:
        addr - the multicast group to which this socket has to be joined.
        Throws:
        IOException - if an error occurs while joining the specified multicast group.
      • joinGroup

        public void joinGroup​(SocketAddress addr,
                              NetworkInterface netInterface)
                       throws IOException
        Description copied from class: DatagramSocketImpl
        Adds this socket to the multicast group addr. A socket must join a group before being able to receive data. Further, a socket may be a member of multiple groups but may join any group only once.
        Specified by:
        joinGroup in class DatagramSocketImpl
        Parameters:
        addr - the multicast group to which this socket has to be joined.
        netInterface - the local network interface which will receive the multicast datagram packets.
        Throws:
        IOException - if an error occurs while joining the specified multicast group.
      • leave

        public void leave​(InetAddress addr)
                   throws IOException
        Description copied from class: DatagramSocketImpl
        Removes this socket from the multicast group addr.
        Specified by:
        leave in class DatagramSocketImpl
        Parameters:
        addr - the multicast group to be left.
        Throws:
        IOException - if an error occurs while leaving the group or no multicast address was assigned.
      • peek

        protected int peek​(InetAddress sender)
                    throws IOException
        Description copied from class: DatagramSocketImpl
        Peeks at the incoming packet to this socket and returns the address of the sender. The method will block until a packet is received or timeout expires.
        Specified by:
        peek in class DatagramSocketImpl
        Parameters:
        sender - the origin address of a packet.
        Returns:
        the address of sender as an integer value.
        Throws:
        IOException - if an error or a timeout occurs while reading the address.
      • receive

        public void receive​(DatagramPacket pack)
                     throws IOException
        Description copied from class: DatagramSocketImpl
        Receives data and stores it in the supplied datagram packet pack. This call will block until either data has been received or, if a timeout is set, the timeout has expired. If the timeout expires an InterruptedIOException is thrown.
        Specified by:
        receive in class DatagramSocketImpl
        Parameters:
        pack - the datagram packet container to fill in the received data.
        Throws:
        IOException - if an error or timeout occurs while receiving data.
      • peekData

        public int peekData​(DatagramPacket pack)
                     throws IOException
        Description copied from class: DatagramSocketImpl
        Receives data into the supplied datagram packet by peeking. The data is not removed from socket buffer and can be received again by another peekData() or receive() call. This call blocks until either data has been received or, if a timeout is set, the timeout has been expired.
        Specified by:
        peekData in class DatagramSocketImpl
        Parameters:
        pack - the datagram packet used to store the data.
        Returns:
        the port the packet was received from.
        Throws:
        IOException - if an error occurs while peeking at the data.
      • send

        public void send​(DatagramPacket packet)
                  throws IOException
        Description copied from class: DatagramSocketImpl
        Sends the given datagram packet pack. The packet contains the data and the address and port information of the target host as well.
        Specified by:
        send in class DatagramSocketImpl
        Parameters:
        packet - the datagram packet to be sent.
        Throws:
        IOException - if an error occurs while sending the packet.
      • setOption

        public void setOption​(int option,
                              Object value)
                       throws SocketException
        Description copied from interface: SocketOptions
        Sets the value of the specified socket option.
        Parameters:
        option - the option identifier.
        value - the value to be set for the option.
        Throws:
        SocketException - if an error occurs setting the option value.
      • setTimeToLive

        public void setTimeToLive​(int ttl)
                           throws IOException
        Description copied from class: DatagramSocketImpl
        Sets the time-to-live (TTL) option for multicast packets sent on this socket.
        Specified by:
        setTimeToLive in class DatagramSocketImpl
        Parameters:
        ttl - the time-to-live option value. Valid values are 0 < ttl <= 255.
        Throws:
        IOException - if an error occurs while setting the option.
      • connect

        public void connect​(InetAddress inetAddr,
                            int port)
                     throws SocketException
        Description copied from class: DatagramSocketImpl
        Connects this socket to the specified remote address and port.
        Overrides:
        connect in class DatagramSocketImpl
        Parameters:
        inetAddr - the address of the target host which has to be connected.
        port - the port on the target host which has to be connected.
        Throws:
        SocketException - if the datagram socket cannot be connected to the specified remote address and port.