當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。