Package java.nio.channels

Examples of java.nio.channels.DatagramChannel.connect()


    DatagramChannel out = DatagramChannel.open();
    try {
      out.configureBlocking(false);
      out.socket().bind(OutAddress);
      if (! send) out.connect(InAddress);
   
      DatagramChannel in = DatagramChannel.open();
      try {
        in.configureBlocking(false);
        in.socket().bind(InAddress);
View Full Code Here


            ((DatagramChannelWithTimeouts) c).setReadTimeout(getTimeoutAsInt());
        } else {
            c = DatagramChannel.open();
        }
        int port = Integer.parseInt(getPort());
        c.connect(new InetSocketAddress(getHostName(), port));
        return c;
    }

    @Override
    public ByteBuffer encode(String data) {
View Full Code Here

            ch.socket().setBroadcast(false);
        } catch (SocketException e) {
            throw new IllegalStateException(e);
        }
        try {
            ch.connect(sockAddr);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        return ch;
    }
View Full Code Here

            }

            if (localAddress != null) {
                ch.socket().bind(localAddress);
            }
            ch.connect(address);
            ch.configureBlocking(false);
            initialized = true;
        } catch (IOException e) {
            return DefaultConnectFuture.newFailedFuture(e);
        } finally {
View Full Code Here

    public static String getRoutingAddress(String targetIP) {
        try {
            DatagramChannel ch = DatagramChannel.open();
            try {
                ch.connect(new InetSocketAddress(targetIP, 7));
                return ch.socket().getLocalAddress().getHostAddress();
            } finally {
                ch.close();
            }
        } catch (IOException e) {
View Full Code Here

            ch.socket().setReuseAddress( true );
            if( localAddress != null )
            {
                ch.socket().bind( localAddress );
            }
            ch.connect( address );
            ch.configureBlocking( false );
            initialized = true;
        }
        finally
        {
View Full Code Here

            throw new IOException("Invalid address");
          }
          if (bind) {
            channel.socket().bind(a);
          } else {
            channel.connect(a);
          }
        } catch (IOException e) {
          selectionKey.cancel();
          throw e;
        }
View Full Code Here

        DatagramChannel channel = DatagramChannel.open();
        channel.configureBlocking(false);
        DatagramSocket socket = channel.socket();
        socket.bind(local);
        channel.connect(remote);
        return channel;
    }

    public static void setupLogging() {
        Logger root = Logger.getRootLogger();
View Full Code Here

            }

            if (localAddress != null) {
                ch.socket().bind(localAddress);
            }
            ch.connect(address);
            ch.configureBlocking(false);
            initialized = true;
        } catch (IOException e) {
            return DefaultConnectFuture.newFailedFuture(e);
        } finally {
View Full Code Here

    public void test_write_LBuffer_positioned() throws Exception {
        // Regression test for Harmony-683
        int position = 16;
        DatagramChannel dc = DatagramChannel.open();
        byte[] sourceArray = new byte[CAPACITY_NORMAL];       
        dc.connect(localAddr1);
        // write
        ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
        sourceBuf.position(position);
        assertEquals(CAPACITY_NORMAL - position, dc.write(sourceBuf));
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.