Code example for DatagramSocket

Methods: getLocalSocketAddress

0
import java.nio.channels.DatagramChannel; 
 
public class DatagramChannelTest extends junit.framework.TestCase {
    public void test_read_intoReadOnlyByteArrays() throws Exception { 
        ByteBuffer readOnly = ByteBuffer.allocate(1).asReadOnlyBuffer();
        DatagramSocket ds = new DatagramSocket(0);
        DatagramChannel dc = DatagramChannel.open();
        dc.connect(ds.getLocalSocketAddress());
        try { 
            dc.read(readOnly);
            fail();
        } catch (IllegalArgumentException expected) {
        } 
        try { 
            dc.read(new ByteBuffer[] { readOnly });
            fail();
        } catch (IllegalArgumentException expected) {
        } 
        try { 
            dc.read(new ByteBuffer[] { readOnly }, 0, 1);
            fail();