本文整理汇总了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() + "]";
}
示例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);
}
示例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();
}
}
示例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) {
}
}
}
示例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();
}
示例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);
}
};
}
示例7: PortUnreachable
import java.net.DatagramSocket; //导入方法依赖的package包/类
PortUnreachable() throws Exception {
clientSock = new DatagramSocket();
clientPort = clientSock.getLocalPort();
}