Code example for DatagramChannel

Methods: connectisConnectedwrite

0
        ByteBuffer[] writeBuf = new ByteBuffer[2];
        writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
        writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
        InetSocketAddress ipAddr = localAddr1;
        try { 
            this.channel1.write(writeBuf, -1, 2);
            fail("should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            // correct 
        } 
        try { 
            this.channel1.write(writeBuf, 0, -1);
            fail("should throw IndexOutOfBoundsException");
        } catch (IndexOutOfBoundsException e) {
            // correct 
        } 
        this.channel1.connect(ipAddr);
        assertTrue(this.channel1.isConnected());
        assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf, 0, 2));
        // cannot be buffered again! 
        assertEquals(0, this.channel1.write(writeBuf, 0, 1));
    } 
 
    public void testWriteByteBufferArrayIntInt_ConnectedIndexBad() 
            throws IOException { 
        ByteBuffer[] writeBuf = new ByteBuffer[2];
Connect your IDE to all the code out there  Get Codota for Java