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


Java DatagramSocket.getLocalPort方法代码示例

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


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

示例1: UdpMultiClientServer

import java.net.DatagramSocket; //导入方法依赖的package包/类
/**
 * 
 * @param socket
 */
public UdpMultiClientServer(DatagramSocket socket) {
	super(DatagramSocket.class);
	this.socket = socket;
	this.port = socket.getLocalPort();
	this.address = socket.getLocalAddress();
	this.isRunning = new AtomicBoolean(false);
	this.name = "UdpMultiClientServer [" + address + ":" + socket.getLocalPort() + "]";
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:13,代码来源:UdpMultiClientServer.java

示例2: VoiceRelay

import java.net.DatagramSocket; //导入方法依赖的package包/类
public VoiceRelay() throws Exception{
    final DatagramSocket sock1 = new DatagramSocket();
    final DatagramSocket sock2 = new DatagramSocket();
    //Log socket ports to terminal
    System.out.println("Address 1: " + Integer.toString(sock1.getLocalPort()));
    System.out.println("Address 2: " + Integer.toString(sock2.getLocalPort()));
    port1 = sock1.getLocalPort();
    port2 = sock2.getLocalPort();
    bridge(sock1, sock2);
    bridge(sock2, sock1);
}
 
开发者ID:rctl,项目名称:CryptoVoice,代码行数:12,代码来源:VoiceRelay.java

示例3: setLocalAddress

import java.net.DatagramSocket; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void setLocalAddress(InetAddress addr) {
	if (isConnected() || !isOpened()) return;
	
	disconnect();
	
	try {
		socket = new DatagramSocket(socket.getLocalPort(), addr);
	} catch (IOException e) {
		e.printStackTrace();
	}
	
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:17,代码来源:UDPCommInterface.java

示例4: main

import java.net.DatagramSocket; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    DatagramSocket s = new DatagramSocket();
    int port = s.getLocalPort();

    for (int i=0; i<32000; i++) {
        try {
            DatagramSocket s2 = new DatagramSocket(port);
        } catch (BindException e) {
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:BindFailTest.java

示例5: getInfo

import java.net.DatagramSocket; //导入方法依赖的package包/类
String getInfo(DatagramSocket soc) {
    if (soc == null) {
        return null;
    }

    return "localPort: " + soc.getLocalPort()
            + "; localAddress: " + soc.getLocalAddress()
            + "; remotePort: " + soc.getPort()
            + "; remoteAddress: " + soc.getInetAddress()
            + "; isClosed: " + soc.isClosed()
            + "; isBound: " + soc.isBound();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ReuseAddressTest.java

示例6: createSnmpClient

import java.net.DatagramSocket; //导入方法依赖的package包/类
public SnmpClient createSnmpClient(
        final InetAddress nodeAddress,
        SimulationEntry entry)
        throws IOException {
    if (nodeAddress == null) {
        throw new IOException("nodeAddress == null");
    }
    if (archive == null) {
        throw new IOException("archive is null");
    }
    if (!archive.exists(nodeAddress.getHostAddress())) {
        throw new IOException("no simulationEntry found: " + nodeAddress.getHostAddress());
    }
    DatagramSocket socket = new DatagramSocket();
    final SnmpAgentEmulator agentEmulator =
            new SnmpAgentEmulator(
                    new ZipFile(archive.getSimulationArchiveFile()),
                    entry.getMibZipEntryName(),
                    socket);
    agentEmulator.start();
    return new SnmpClient(
            InetAddress.getLocalHost(),
            socket.getLocalPort(),
            "public".getBytes(),
            new SnmpClientLogger()) {
        public void close() {
            try {
                agentEmulator.stop();
            } catch (Exception e) {
                log.info(e.toString());
            }
        }

        public InetSocketAddress getSnmpAgentAddress() {
            return new InetSocketAddress(nodeAddress, 0);
        }
    };
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:39,代码来源:SimulatedSnmpClientFactory.java

示例7: PortUnreachable

import java.net.DatagramSocket; //导入方法依赖的package包/类
PortUnreachable() throws Exception {

        clientSock = new DatagramSocket();
        clientPort = clientSock.getLocalPort();

    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:PortUnreachable.java


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