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


Java ServerSocket.getLocalSocketAddress方法代码示例

本文整理汇总了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();
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:14,代码来源:MockSmtpServer.java

示例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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MockTcpTransport.java

示例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() };
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:8,代码来源:Zab1_0Test.java

示例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() };
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:8,代码来源:Zab1_0Test.java

示例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;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:33,代码来源:AcceptorImpl.java

示例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;
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:10,代码来源:QuorumCnxManagerTest.java

示例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);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:54,代码来源:Zab1_0Test.java

示例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);
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:53,代码来源:Zab1_0Test.java


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