当前位置: 首页>>代码示例>>Java>>正文


Java DatagramChannel.connect方法代码示例

本文整理汇总了Java中java.nio.channels.DatagramChannel.connect方法的典型用法代码示例。如果您正苦于以下问题:Java DatagramChannel.connect方法的具体用法?Java DatagramChannel.connect怎么用?Java DatagramChannel.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.DatagramChannel的用法示例。


在下文中一共展示了DatagramChannel.connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: launchWithDatagramChannel

import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
public static DatagramChannel launchWithDatagramChannel(String className, String options[], String args[])
    throws IOException
{
    DatagramChannel dc = DatagramChannel.open();
    dc.socket().bind(new InetSocketAddress(0));

    int port = dc.socket().getLocalPort();
    launch(className, options, args, Util.getFD(dc));
    dc.close();

    dc = DatagramChannel.open();
    InetAddress address = InetAddress.getLocalHost();
    if (address.isLoopbackAddress()) {
        address = InetAddress.getLoopbackAddress();
    }
    InetSocketAddress isa = new InetSocketAddress(address, port);

    dc.connect(isa);
    return dc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:Launcher.java

示例2: run

import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
public void run() {
    try {
        DatagramChannel dc = DatagramChannel.open();
        ByteBuffer bb = ByteBuffer.allocateDirect(12);
        bb.order(ByteOrder.BIG_ENDIAN);
        bb.putInt(1).putLong(1);
        bb.flip();
        InetAddress address = InetAddress.getLocalHost();
        InetSocketAddress isa = new InetSocketAddress(address, port);
        dc.connect(isa);
        clientISA = dc.getLocalAddress();
        dc.write(bb);
    } catch (Exception ex) {
        e = ex;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Sender.java

示例3: main

import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    InetAddress lh = InetAddress.getLocalHost();
    SocketAddress remote = new InetSocketAddress(lh, 1234);

    DatagramSocket ds = null;
    DatagramChannel dc = null;
    try {

        ds = new DatagramSocket();
        dc = DatagramChannel.open().bind(new InetSocketAddress(0));
        check(ds, dc);

        ds.connect(remote);
        dc.connect(remote);
        check(ds, dc);

        ds.disconnect();
        dc.disconnect();
        check(ds, dc);

        // repeat tests using socket adapter
        ds.connect(remote);
        dc.socket().connect(remote);
        check(ds, dc);

        ds.disconnect();
        dc.socket().disconnect();
        check(ds, dc);

   } finally {
        if (ds != null) ds.close();
        if (dc != null) dc.close();
   }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:ChangingAddress.java

示例4: test

import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
private static void test() throws Exception {
    DatagramChannel dc = DatagramChannel.open();
    InetAddress localHost = InetAddress.getLocalHost();
    dc.bind(new InetSocketAddress(localHost, 0));

    Server server = new Server(dc.getLocalAddress());
    Thread serverThread = new Thread(server);
    serverThread.start();

    try {
        InetSocketAddress isa = new InetSocketAddress(localHost, server.port());
        dc.connect(isa);

        ByteBuffer bb = ByteBuffer.allocateDirect(12);
        bb.order(ByteOrder.BIG_ENDIAN);
        bb.putInt(1).putLong(1);
        bb.flip();

        dc.write(bb);
        bb.rewind();
        dc.write(bb);
        bb.rewind();
        dc.write(bb);

        Thread.sleep(2000);

        serverThread.interrupt();
        server.throwException();
    } finally {
        dc.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:EmptyBuffer.java

示例5: connect

import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
@Override
protected boolean connect(DatagramChannel handle, SocketAddress remoteAddress) throws Exception {
    handle.connect(remoteAddress);
    return true;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:6,代码来源:NioDatagramConnector.java

示例6: createChannel

import java.nio.channels.DatagramChannel; //导入方法依赖的package包/类
private DatagramChannel createChannel() throws IOException {
    logi(TAG, "Open");
    DatagramChannel datagramChannel = DatagramChannel.open();
    datagramChannel.configureBlocking(false);
    datagramChannel.connect(getRewrittenDestination());
    return datagramChannel;
}
 
开发者ID:Genymobile,项目名称:gnirehtet,代码行数:8,代码来源:UDPConnection.java


注:本文中的java.nio.channels.DatagramChannel.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。