DatagramChannel isConnected - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for DatagramChannel isConnected method.

This code example shows how to use the following methods:isConnected, socket, isOpen, isRegistered
     *  
     * @return 
     */ 
    public String getDatagramChannelState() {
        String state = "";
        if (this.datagramChannel.isOpen() ) {
            state += "OPEN";
        } else { 
            return "CLOSED"; 
        }  
         
        if ( this.datagramChannel.isRegistered() ) {
             state += " REGISTERED";
        } else { 
            return state + " NOT_REGISTERED";
        } 
         
        if ( this.datagramChannel.isConnected()) {
            state += " CONNECTED";
        } else { 

6
CodeRank
This code example shows how to use the following methods:disconnect, isConnected, socket, close
        } catch (IOException iox) 
        { 
            // ignore 
        } 
         
        if (!channel.socket().isClosed()) {
            channel.socket().close();
        } 
 
        try { 
            if (channel.isConnected())
                channel.disconnect();
        } catch (IOException iox) 
        { 
           // ignore 
        } 
         
        try { 
            channel.close();
        } catch (IOException iox) {

5
CodeRank
This code example shows how to use the following methods:isConnected, close
 
	public void close() { 
		super.close(); 
 
		try { 
			if (channel.isConnected()) {
				try { 
					channel.close();
				} 
				catch (IOException e) {
					throw new RuntimeException(e);
				} 
			} 
		} 
		finally { 
			channel = null;
		} 
	} 
} 
5
CodeRank
This code example shows how to use the following methods:isConnected, read, receive
    } 
    @Override 
    public int read(ByteBuffer buffer) throws IOException {
        if (!isConnected()) { 
            int position = buffer.position();
            address = mChannel.receive(buffer);
            if (address == null)
                return -1; 
            return buffer.position() - position;
        } 
        address = null;
        return mChannel.read(buffer);
    } 
    @Override 
    public boolean isConnected() { 
        return mChannel.isConnected();
    } 
    @Override 
    public int write(ByteBuffer src) throws IOException {
        return mChannel.write(src);
    } 
5
CodeRank
This code example shows how to use the following methods:disconnect, isConnected, socket, close
        } catch (IOException iox) 
        { 
            // ignore 
        } 
         
        if (!channel.socket().isClosed()) {
            channel.socket().close();
        } 
 
        try { 
            if (channel.isConnected())
                channel.disconnect();
        } catch (IOException iox) 
        { 
           // ignore 
        } 
         
        try { 
            channel.close();
        } catch (IOException iox) {

5
CodeRank
This code example shows how to use the following methods:connect, isConnected, send, isOpen, isBlocking
    // ------------------------------------------------------------------- 
 
    private void sendDataBlocking(InetSocketAddress addr, ByteBuffer writeBuf)
            throws IOException {
        InetSocketAddress ipAddr = addr;
        assertEquals(CAPACITY_NORMAL, this.channel1.send(writeBuf, ipAddr));
        assertTrue(this.channel1.isOpen());
        assertTrue(this.channel1.isBlocking());
        this.channel1.connect(ipAddr);
        assertTrue(this.channel1.isConnected());
    } 
 
    private void sendDataNonBlocking(InetSocketAddress addr, ByteBuffer writeBuf)
            throws IOException {
        InetSocketAddress ipAddr = addr;
        this.channel1.configureBlocking(false);
        assertEquals(CAPACITY_NORMAL, this.channel1.send(writeBuf, ipAddr));
        assertTrue(this.channel1.isOpen());
        assertFalse(this.channel1.isBlocking());
        this.channel1.connect(ipAddr);

4
CodeRank
This code example shows how to use the following methods:isConnected
    protected void implConfigureBlocking(boolean block) throws IOException {
        throw new UnsupportedOperationException("This class is blocking implementation of SocketChannel");
    } 
 
    public boolean isConnected() { 
        return channel.isConnected();
    } 
 
    public void setReadTimeout(int t) {
        readTimeout = t;
    } 
 
    public DatagramSocket socket() {
        return channel.socket();
    } 
 
    public DatagramChannel disconnect() throws IOException {
        return channel.disconnect();
    } 
 
4
CodeRank
This code example shows how to use the following methods:connect, isConnected, write
 
    public void testWriteByteBuffer_Block_BufNull() throws IOException { 
        ByteBuffer writeBuf = ByteBuffer.allocateDirect(0);
        InetSocketAddress ipAddr = localAddr1;
        try { 
            this.channel1.write((ByteBuffer) null);
            fail("Should throw NPE.");
        } catch (NullPointerException e) {
            // correct 
        } 
        this.channel1.connect(ipAddr);
        assertTrue(this.channel1.isConnected());
        try { 
            this.channel1.write((ByteBuffer) null);
            fail("Should throw NPE.");
        } catch (NullPointerException e) {
            // correct 
        } 
        assertEquals(0, this.channel1.write(writeBuf));
        datagramSocket1.close();

2
CodeRank
This code example shows how to use the following methods:isConnected
    protected void implConfigureBlocking(boolean block) throws IOException {
        throw new UnsupportedOperationException("This class is blocking implementation of SocketChannel");
    } 
 
    public boolean isConnected() { 
        return channel.isConnected();
    } 
 
    public void setReadTimeout(int t) {
        readTimeout = t;
    } 
 
    public DatagramSocket socket() {
        return channel.socket();
    } 
 
    public DatagramChannel disconnect() throws IOException {
        return channel.disconnect();
    } 
 
4
CodeRank
isConnected Method Overview
Tells whether or not this channel's socket is connected.
See Code Examples for other Java 8 DatagramChannel Methods: