本文整理汇总了Java中java.net.ServerSocket.getLocalSocketAddress方法的典型用法代码示例。如果您正苦于以下问题:Java ServerSocket.getLocalSocketAddress方法的具体用法?Java ServerSocket.getLocalSocketAddress怎么用?Java ServerSocket.getLocalSocketAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.ServerSocket
的用法示例。
在下文中一共展示了ServerSocket.getLocalSocketAddress方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import java.net.ServerSocket; //导入方法依赖的package包/类
public void start() throws IOException {
checkServerNotRunning();
InetAddress localAddress = InetAddress.getByName(null);
ServerSocket serverSocket = new ServerSocket(0, 1, localAddress);
InetSocketAddress localSocketAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
host = localSocketAddress.getHostString();
port = serverSocket.getLocalPort();
mockServerThread = new MockServerThread(serverSocket, interactions, waitForConnectionClosed,
waitForAllExpectedCommands, logger, keyStoreProvider);
mockServerThread.start();
}
示例2: MockChannel
import java.net.ServerSocket; //导入方法依赖的package包/类
/**
* Constructs a new MockChannel instance intended for accepting requests.
*
* @param serverSocket The associated server socket. Must not be null.
* @param profile The associated profile name.
*/
public MockChannel(ServerSocket serverSocket, String profile) {
this.localAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
this.serverSocket = serverSocket;
this.profile = profile;
this.activeChannel = null;
this.onClose = null;
synchronized (openChannels) {
openChannels.add(this);
}
}
示例3: getSocketPair
import java.net.ServerSocket; //导入方法依赖的package包/类
static Socket[] getSocketPair() throws IOException {
ServerSocket ss = new ServerSocket();
ss.bind(null);
InetSocketAddress endPoint = (InetSocketAddress) ss.getLocalSocketAddress();
Socket s = new Socket(endPoint.getAddress(), endPoint.getPort());
return new Socket[] { s, ss.accept() };
}
示例4: getSocketPair
import java.net.ServerSocket; //导入方法依赖的package包/类
static Socket[] getSocketPair() throws IOException {
ServerSocket ss =
new ServerSocket(0, 50, InetAddress.getByName("127.0.0.1"));
InetSocketAddress endPoint = (InetSocketAddress) ss.getLocalSocketAddress();
Socket s = new Socket(endPoint.getAddress(), endPoint.getPort());
return new Socket[] { s, ss.accept() };
}
示例5: getExternalAddress
import java.net.ServerSocket; //导入方法依赖的package包/类
/**
* Gets the address that this bridge server can be contacted on from external processes.
*
* @since GemFire 5.7
*/
public String getExternalAddress() {
String result = this.bindHostName;
boolean needCanonicalHostName = false;
if (result == null || "".equals(result)) {
needCanonicalHostName = true;
} else {
// check to see if we are listening on all local addresses
ServerSocket ss = this.serverSock;
if (ss != null && ss.getLocalSocketAddress() instanceof InetSocketAddress) {
InetSocketAddress isa = (InetSocketAddress) ss.getLocalSocketAddress();
InetAddress ssAddr = isa.getAddress();
if (ssAddr != null) {
if (ssAddr.isAnyLocalAddress()) {
needCanonicalHostName = true;
}
}
}
}
if (needCanonicalHostName) {
try {
result = SocketCreator.getLocalHost().getCanonicalHostName();
} catch (UnknownHostException ex) {
throw new IllegalStateException("getLocalHost failed with " + ex);
}
}
return result;
}
示例6: getSocketPair
import java.net.ServerSocket; //导入方法依赖的package包/类
private static Socket getSocketPair() throws IOException {
ServerSocket ss = new ServerSocket();
ss.bind(null);
InetSocketAddress endPoint = (InetSocketAddress) ss
.getLocalSocketAddress();
Socket s = new Socket(endPoint.getAddress(), endPoint.getPort());
s.setSoTimeout(5000);
return s;
}
示例7: testFollowerConversation
import java.net.ServerSocket; //导入方法依赖的package包/类
public void testFollowerConversation(FollowerConversation conversation) throws Exception {
File tmpDir = File.createTempFile("test", "dir", testData);
tmpDir.delete();
tmpDir.mkdir();
Thread followerThread = null;
ConversableFollower follower = null;
QuorumPeer peer = null;
try {
peer = createQuorumPeer(tmpDir);
follower = createFollower(tmpDir, peer);
peer.follower = follower;
ServerSocket ss = new ServerSocket();
ss.bind(null);
QuorumServer leaderQS = new QuorumServer(1,
(InetSocketAddress) ss.getLocalSocketAddress());
follower.setLeaderQuorumServer(leaderQS);
final Follower followerForThread = follower;
followerThread = new Thread() {
public void run() {
try {
followerForThread.followLeader();
} catch (InterruptedException e) {
LOG.info("Follower thread interrupted", e);
} catch (Exception e) {
LOG.warn("Unexpected exception in follower thread", e);
}
}
};
followerThread.start();
Socket leaderSocket = ss.accept();
InputArchive ia = BinaryInputArchive.getArchive(leaderSocket
.getInputStream());
OutputArchive oa = BinaryOutputArchive.getArchive(leaderSocket
.getOutputStream());
conversation.converseWithFollower(ia, oa, follower);
} finally {
if (follower != null) {
follower.shutdown();
}
if (followerThread != null) {
followerThread.interrupt();
followerThread.join();
}
if (peer != null) {
peer.shutdown();
}
recursiveDelete(tmpDir);
}
}
示例8: testObserverConversation
import java.net.ServerSocket; //导入方法依赖的package包/类
public void testObserverConversation(ObserverConversation conversation) throws Exception {
File tmpDir = File.createTempFile("test", "dir", testData);
tmpDir.delete();
tmpDir.mkdir();
Thread observerThread = null;
ConversableObserver observer = null;
QuorumPeer peer = null;
try {
peer = createQuorumPeer(tmpDir);
peer.setSyncEnabled(true);
observer = createObserver(tmpDir, peer);
peer.observer = observer;
ServerSocket ss = new ServerSocket();
ss.bind(null);
QuorumServer leaderQS = new QuorumServer(1,
(InetSocketAddress) ss.getLocalSocketAddress());
observer.setLeaderQuorumServer(leaderQS);
final Observer observerForThread = observer;
observerThread = new Thread() {
public void run() {
try {
observerForThread.observeLeader();
} catch(Exception e) {
e.printStackTrace();
}
}
};
observerThread.start();
Socket leaderSocket = ss.accept();
InputArchive ia = BinaryInputArchive.getArchive(leaderSocket
.getInputStream());
OutputArchive oa = BinaryOutputArchive.getArchive(leaderSocket
.getOutputStream());
conversation.converseWithObserver(ia, oa, observer);
} finally {
if (observer != null) {
observer.shutdown();
}
if (observerThread != null) {
observerThread.interrupt();
observerThread.join();
}
if (peer != null) {
peer.shutdown();
}
recursiveDelete(tmpDir);
}
}