IT. Expert System.

Android Reference

DatagramChannel


java.nio.channels

Class DatagramChannel

    • Constructor Detail

      • DatagramChannel

        protected DatagramChannel(SelectorProvider selectorProvider)
        Constructs a new DatagramChannel.
        Parameters:
        selectorProvider - an instance of SelectorProvider.
    • Method Detail

      • open

        public static DatagramChannel open()
                                    throws IOException
        Creates an opened and not-connected datagram channel.

        This channel is created by calling the openDatagramChannel method of the default SelectorProvider instance.

        Returns:
        the new channel which is open but not connected.
        Throws:
        IOException - if some I/O error occurs.
      • validOps

        public final int validOps()
        Gets the valid operations of this channel. Datagram channels support read and write operations, so this method returns ( SelectionKey.OP_READ | SelectionKey.OP_WRITE ).
        Specified by:
        validOps in class SelectableChannel
        Returns:
        valid operations in bit-set.
        See Also:
        SelectableChannel.validOps()
      • socket

        public abstract DatagramSocket socket()
        Returns the related datagram socket of this channel, which does not define additional public methods to those defined by DatagramSocket.
        Returns:
        the related DatagramSocket instance.
      • isConnected

        public abstract boolean isConnected()
        Returns whether this channel's socket is connected or not.
        Returns:
        true if this channel's socket is connected; false otherwise.
      • connect

        public abstract DatagramChannel connect(SocketAddress address)
                                         throws IOException
        Connects the socket of this channel to a remote address, which is the only communication peer for getting and sending datagrams after being connected.

        This method can be called at any time without affecting the read and write operations being processed at the time the method is called. The connection status does not change until the channel is disconnected or closed.

        This method executes the same security checks as the connect method of the DatagramSocket class.

        Parameters:
        address - the address to be connected to.
        Returns:
        this channel.
        Throws:
        ClosedChannelException - if the channel is already closed.
        AsynchronousCloseException - if the channel is closed by another thread while this method is in operation.
        ClosedByInterruptException - if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.
        IOException - if some other I/O error occurs.
      • disconnect

        public abstract DatagramChannel disconnect()
                                            throws IOException
        Disconnects the socket of this channel, which has been connected before in order to send and receive datagrams.

        This method can be called at any time without affecting the read and write operations being underway. It does not have any effect if the socket is not connected or the channel is closed.

        Returns:
        this channel.
        Throws:
        IOException - some other I/O error occurs.
      • receive

        public abstract SocketAddress receive(ByteBuffer target)
                                       throws IOException
        Gets a datagram from this channel.

        This method transfers a datagram from the channel into the target byte buffer. If this channel is in blocking mode, it waits for the datagram and returns its address when it is available. If this channel is in non-blocking mode and no datagram is available, it returns null immediately. The transfer starts at the current position of the buffer, and if there is not enough space remaining in the buffer to store the datagram then the part of the datagram that does not fit is discarded.

        This method can be called at any time and it will block if there is another thread that has started a read operation on the channel.

        This method executes the same security checks as the receive method of the DatagramSocket class.

        Parameters:
        target - the byte buffer to store the received datagram.
        Returns:
        the address of the datagram if the transfer is performed, or null if the channel is in non-blocking mode and no datagram is available.
        Throws:
        ClosedChannelException - if the channel is already closed.
        AsynchronousCloseException - if the channel is closed by another thread while this method is in operation.
        ClosedByInterruptException - if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.
        IOException - some other I/O error occurs.
      • send

        public abstract int send(ByteBuffer source,
               SocketAddress address)
                          throws IOException
        Sends a datagram through this channel. The datagram consists of the remaining bytes in source.

        If this channel is in blocking mode then the datagram is sent as soon as there is enough space in the underlying output buffer. If this channel is in non-blocking mode then the datagram is only sent if there is enough space in the underlying output buffer at that moment. The transfer action is just like a regular write operation.

        This method can be called at any time and it will block if another thread has started a send operation on this channel.

        This method executes the same security checks as the send method of the DatagramSocket class.

        Parameters:
        source - the byte buffer with the datagram to be sent.
        address - the destination address for the datagram.
        Returns:
        the number of bytes sent. This is the number of bytes remaining in source or zero if the channel is in non-blocking mode and there is not enough space for the datagram in the underlying output buffer.
        Throws:
        ClosedChannelException - if the channel is already closed.
        AsynchronousCloseException - if the channel is closed by another thread while this method is in operation.
        ClosedByInterruptException - if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.
        IOException - some other I/O error occurs.
      • read

        public abstract int read(ByteBuffer target)
                          throws IOException
        Reads a datagram from this channel into the byte buffer.

        The precondition for calling this method is that the channel is connected and the incoming datagram is from the connected address. If the buffer is not big enough to store the datagram, the part of the datagram that does not fit in the buffer is discarded. Otherwise, this method has the same behavior as the read method in the ReadableByteChannel interface.

        Specified by:
        read in interface ReadableByteChannel
        Parameters:
        target - the byte buffer to store the received datagram.
        Returns:
        a non-negative number as the number of bytes read, or -1 as the read operation reaches the end of stream.
        Throws:
        NotYetConnectedException - if the channel is not connected yet.
        ClosedChannelException - if the channel is already closed.
        AsynchronousCloseException - if the channel is closed by another thread while this method is in operation.
        ClosedByInterruptException - if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.
        IOException - some other I/O error occurs.
        See Also:
        ReadableByteChannel.read(java.nio.ByteBuffer)
      • read

        public abstract long read(ByteBuffer[] targets,
                int offset,
                int length)
                           throws IOException
        Reads a datagram from this channel into an array of byte buffers.

        The precondition for calling this method is that the channel is connected and the incoming datagram is from the connected address. If the buffers do not have enough remaining space to store the datagram, the part of the datagram that does not fit in the buffers is discarded. Otherwise, this method has the same behavior as the read method in the ScatteringByteChannel interface.

        Specified by:
        read in interface ScatteringByteChannel
        Parameters:
        targets - the byte buffers to store the received datagram.
        offset - a non-negative offset in the array of buffers, pointing to the starting buffer to store the bytes transferred, must not be bigger than targets.length.
        length - a non-negative length to indicate the maximum number of buffers to be filled, must not be bigger than targets.length - offset.
        Returns:
        a non-negative number as the number of bytes read, or -1 if the read operation reaches the end of stream.
        Throws:
        NotYetConnectedException - if the channel is not connected yet.
        ClosedChannelException - if the channel is already closed.
        AsynchronousCloseException - if the channel is closed by another thread while this method is in operation.
        ClosedByInterruptException - if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.
        IOException - some other I/O error occurs.
        See Also:
        ScatteringByteChannel.read(java.nio.ByteBuffer[], int, int)
      • read

        public final long read(ByteBuffer[] targets)
                        throws IOException
        Reads a datagram from this channel into an array of byte buffers.

        The precondition for calling this method is that the channel is connected and the incoming datagram is from the connected address. If the buffers do not have enough remaining space to store the datagram, the part of the datagram that does not fit in the buffers is discarded. Otherwise, this method has the same behavior as the read method in the ScatteringByteChannel interface.

        Specified by:
        read in interface ScatteringByteChannel
        Parameters:
        targets - the byte buffers to store the received datagram.
        Returns:
        a non-negative number as the number of bytes read, or -1 if the read operation reaches the end of stream.
        Throws:
        NotYetConnectedException - if the channel is not connected yet.
        ClosedChannelException - if the channel is already closed.
        AsynchronousCloseException - if the channel is closed by another thread while this method is in operation.
        ClosedByInterruptException - if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.
        IOException - some other I/O error occurs.
        See Also:
        ScatteringByteChannel.read(java.nio.ByteBuffer[])
      • write

        public abstract long write(ByteBuffer[] sources,
                 int offset,
                 int length)
                            throws IOException
        Writes a datagram from the byte buffers to this channel.

        The precondition of calling this method is that the channel is connected and the datagram is sent to the connected address. Otherwise, this method has the same behavior as the write method in the GatheringByteChannel interface.

        Specified by:
        write in interface GatheringByteChannel
        Parameters:
        sources - the byte buffers as the source of the datagram.
        offset - a non-negative offset in the array of buffers, pointing to the starting buffer to be retrieved, must be no larger than sources.length.
        length - a non-negative length to indicate the maximum number of buffers to be submitted, must be no bigger than sources.length - offset.
        Returns:
        the number of bytes written. If this method is called, it returns the number of bytes that where remaining in the byte buffers. If the channel is in non-blocking mode and there was not enough space for the datagram in the buffer, it may return zero.
        Throws:
        NotYetConnectedException - if the channel is not connected yet.
        ClosedChannelException - if the channel is already closed.
        AsynchronousCloseException - if the channel is closed by another thread while this method is in operation.
        ClosedByInterruptException - if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.
        IOException - some other I/O error occurs.
        See Also:
        GatheringByteChannel.write(java.nio.ByteBuffer[], int, int)
      • write

        public final long write(ByteBuffer[] sources)
                         throws IOException
        Writes a datagram from the byte buffers to this channel.

        The precondition of calling this method is that the channel is connected and the datagram is sent to the connected address. Otherwise, this method has the same behavior as the write method in the GatheringByteChannel interface.

        Specified by:
        write in interface GatheringByteChannel
        Parameters:
        sources - the byte buffers as the source of the datagram.
        Returns:
        the number of bytes written. If this method is called, it returns the number of bytes that where remaining in the byte buffer. If the channel is in non-blocking mode and there was not enough space for the datagram in the buffer, it may return zero.
        Throws:
        NotYetConnectedException - if the channel is not connected yet.
        ClosedChannelException - if the channel is already closed.
        AsynchronousCloseException - if the channel is closed by another thread while this method is in operation.
        ClosedByInterruptException - if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.
        IOException - some other I/O error occurs.
        See Also:
        GatheringByteChannel.write(java.nio.ByteBuffer[])


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 1493 / . Delta: 0.02385 с