DatagramChannel connect - 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 connect method.

This code example shows how to use the following methods:connect, socket, configureBlocking, register
            socketChannel.socket().setReuseAddress(getSoReuseAddress());
            socketChannel.socket().setOOBInline(getOoBInline());
            socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
            socketChannel.socket().setTrafficClass(getSoTrafficClass());
        } else if (dataChannel!=null) {
            dataChannel.configureBlocking(false);
            dataChannel.socket().setSendBufferSize(getUdpTxBufSize());
            dataChannel.socket().setReceiveBufferSize(getUdpRxBufSize());
            dataChannel.socket().setSoTimeout((int)getTimeout());
            dataChannel.socket().setReuseAddress(getSoReuseAddress());
            dataChannel.socket().setTrafficClass(getSoTrafficClass());
        } 
    } 
 
    private void completeConnect() { 
        //we connected, register ourselves for writing 
        setConnected(true); 
        connecting = false;
        setRequestCount(0); 
        setConnectTime(System.currentTimeMillis());

6
CodeRank
This code example shows how to use the following methods:connect, socket, register, configureBlocking
 
		//trigger_buf.put(trigger_bytes); 
	    //trigger_buf.flip(); 
		 
		channel = DatagramChannel.open();
		channel.configureBlocking(false);
		channel.socket().bind(new InetSocketAddress(video_port));
		channel.connect(new InetSocketAddress(drone_addr, video_port));
		 
		 
		selector = Selector.open();
		channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
	} 
 
	private void disconnect() { 
		Log.v("Drone Control", "Video Reader: Told to disconnect");
		try { 
			selector.close();
		} catch (IOException iox) {
			// Ignore 
6
CodeRank
This code example shows how to use the following methods:connect, socket, register, configureBlocking
    } 
 
    private void connect() throws IOException, ClosedChannelException { 
         
        channel = DatagramChannel.open();
        channel.configureBlocking(false);
        channel.socket().bind(new InetSocketAddress(data_port));
        channel.connect(new InetSocketAddress(drone_addr, data_port));
 
        selector = Selector.open();
        channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
    } 
 
    private void disconnect() { 
        try { 
            if (selector.isOpen())
                selector.close();
        } catch (IOException iox) 
        { 
            // ignore 
6
CodeRank
This code example shows how to use the following methods:connect, socket, configureBlocking
 
	public NavDataReader(ARDrone drone, InetAddress drone_addr, int navdata_port) throws IOException {
		this.drone = drone;
 
		channel = DatagramChannel.open();
		channel.configureBlocking(false);
		channel.socket().bind(new InetSocketAddress(navdata_port));
		channel.connect(new InetSocketAddress(drone_addr, navdata_port));
 
		selector = Selector.open();
	} 
 
	private void disconnect() { 
		try { 
			selector.close();
		} catch (IOException iox) {
			// Ignore 
		} 
 
		try { 
5
CodeRank
This code example shows how to use the following methods:connect, socket, register, configureBlocking
            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 

5
CodeRank
This code example shows how to use the following methods:connect, configureBlocking
 
	public void testProcessCommand() throws IOException { 
		System.out.println("processCommand");
		String toString = "test\ntest\nerr\n";
		final DatagramChannel channel = DatagramChannelEmul.open();
		channel.configureBlocking(false);
		final InetSocketAddress inetSocketAddress = new InetSocketAddress(
				"localhost", 4444); 
		channel.connect(inetSocketAddress);
		PerfMonMetricGetter instance = new PerfMonMetricGetter(
				SigarProxyCache.newInstance(new Sigar(), 500), 
				new PerfMonWorker(), channel, inetSocketAddress);
		instance.addCommandString(toString);
		instance.processNextCommand();
		instance.processNextCommand();
		try { 
			instance.processNextCommand();
			fail();
		} catch (UnsupportedOperationException e) {
		} 
5
CodeRank
This code example shows how to use the following methods:connect, socket, register, configureBlocking
This code example shows how to use the following methods:connect, isConnected, receive, close, isOpen
        assertSame(this.channel1, this.channel1.connect(localAddr1));
        assertTrue(this.channel1.isConnected());
    } 
 
    private void connectWithoutServer() throws IOException {
        assertFalse(this.channel1.isConnected());
        this.datagramSocket1.close();
        assertTrue(this.datagramSocket1.isClosed());
        assertSame(this.channel1, this.channel1.connect(localAddr1));
        assertTrue(this.channel1.isConnected());
    } 
 
    // ------------------------------------------------------------------- 
    // Test for disconnect() 
    // ------------------------------------------------------------------- 
 
    /** 
     * Test method for 'DatagramChannelImpl.disconnect()' 
     * 
     * @throws IOException 

4
CodeRank
This code example shows how to use the following methods:connect, configureBlocking
     */ 
    public void testProcessCommand() throws IOException { 
        System.out.println("processCommand");
        String toString = "test\ntest\nerr\n";
        final DatagramChannel channel = DatagramChannelEmul.open();
        channel.configureBlocking(false);
        final InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 4444);
        channel.connect(inetSocketAddress);
        PerfMonMetricGetter instance = new PerfMonMetricGetter(SigarProxyCache.newInstance(new Sigar(), 500), new PerfMonWorker(), channel, inetSocketAddress);
        instance.addCommandString(toString);
        instance.processNextCommand();
        instance.processNextCommand();
        try { 
            instance.processNextCommand();
            fail();
        } catch (UnsupportedOperationException e) {
        } 
    } 
 
    /** 
5
CodeRank
This code example shows how to use the following methods:connect, close
 
	private void closeChannel(final boolean inResponseToAnEarlierException)
	{ 
		try 
		{ 
			channel.close();
		} 
		catch (IOException e)
		{ 
			if (inResponseToAnEarlierException)
			{ 
				return; 
			} 
			throw new IllegalStateException(e);
		} 
	} 
 
	private void connect(final SocketAddress remoteSocketAddress)
	{ 
		try 

4
CodeRank
connect Method Overview
Connects this channel's socket.
See Code Examples for other Java 8 DatagramChannel Methods: