Code example for DatagramChannel

Methods: socket

0
            socketChannel.socket().setReuseAddress(getSoReuseAddress());
            socketChannel.socket().setOOBInline(getOoBInline());
            socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
            socketChannel.socket().setTrafficClass(getSoTrafficClass());
        } else if (dataChannel!=null) {
            dataChannel.socket().setSendBufferSize(getUdpTxBufSize());
            dataChannel.socket().setReceiveBufferSize(getUdpRxBufSize());
            dataChannel.socket().setSoTimeout((int)getTimeout());
            dataChannel.socket().setReuseAddress(getSoReuseAddress());
            dataChannel.socket().setTrafficClass(getSoTrafficClass());
        } 
    } 
 
 
 
    protected boolean read(SelectionKey key) throws IOException {
        //if there is no message here, we are done 
        if ( current == null ) return true;
        int read = isUdpBased()?dataChannel.read(readbuf) : socketChannel.read(readbuf);
        //end of stream 
        if ( read == -1 ) throw new IOException("Unable to receive an ack message. EOF on socket channel has been reached.");