+doc #19429 initial merge of docs-dev and docs
This commit is contained in:
parent
be0c8af4c0
commit
5a18d43435
501 changed files with 9876 additions and 3681 deletions
31
akka-docs/rst/java/code/docs/util/SocketUtils.java
Normal file
31
akka-docs/rst/java/code/docs/util/SocketUtils.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package docs.util;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
|
||||
public class SocketUtils {
|
||||
|
||||
public static InetSocketAddress temporaryServerAddress(String hostname) {
|
||||
try {
|
||||
ServerSocket socket = ServerSocketChannel.open().socket();
|
||||
socket.bind(new InetSocketAddress(hostname, 0));
|
||||
InetSocketAddress address = new InetSocketAddress(hostname, socket.getLocalPort());
|
||||
socket.close();
|
||||
return address;
|
||||
}
|
||||
catch (IOException io) {
|
||||
throw new RuntimeException(io);
|
||||
}
|
||||
}
|
||||
|
||||
public static InetSocketAddress temporaryServerAddress() {
|
||||
return temporaryServerAddress("127.0.0.1");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue