java.net.ServerSocket.getLocalSocketAddress()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中java.net.ServerSocket.getLocalSocketAddress()方法的一些代码示例,展示了ServerSocket.getLocalSocketAddress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServerSocket.getLocalSocketAddress()方法的具体详情如下:
包路径:java.net.ServerSocket
类名称:ServerSocket
方法名:getLocalSocketAddress

ServerSocket.getLocalSocketAddress介绍

[英]Gets the local socket address of this server socket or null if the socket is unbound. This is useful on multihomed hosts.
[中]

代码示例

代码示例来源:origin: netty/netty

  1. @Override
  2. public SocketAddress run() {
  3. return socket.getLocalSocketAddress();
  4. }
  5. });

代码示例来源:origin: redisson/redisson

  1. @Override
  2. public SocketAddress run() {
  3. return socket.getLocalSocketAddress();
  4. }
  5. });

代码示例来源:origin: wildfly/wildfly

  1. @Override
  2. public SocketAddress run() {
  3. return socket.getLocalSocketAddress();
  4. }
  5. });

代码示例来源:origin: wildfly/wildfly

  1. public SocketAddress getLocalAddress() {
  2. return socket.getLocalSocketAddress();
  3. }

代码示例来源:origin: wildfly/wildfly

  1. public SocketAddress getLocalAddress() {
  2. return socket.getLocalSocketAddress();
  3. }

代码示例来源:origin: apache/activemq

  1. @Override
  2. public InetSocketAddress getSocketAddress() {
  3. return (InetSocketAddress) serverSocket.getLocalSocketAddress();
  4. }

代码示例来源:origin: apache/zookeeper

  1. @Override
  2. public InetSocketAddress getLocalAddress(){
  3. return (InetSocketAddress)ss.socket().getLocalSocketAddress();
  4. }

代码示例来源:origin: Alluxio/alluxio

  1. /** This method will close the socket upon first initialization. */
  2. protected SocketAddress getRpcAddressFromBindSocket() throws IOException {
  3. Preconditions.checkNotNull(mRpcBindSocket, "mRpcBindSocket");
  4. SocketAddress addr = mRpcBindSocket.getLocalSocketAddress();
  5. mRpcBindSocket.close();
  6. return addr;
  7. }
  8. }

代码示例来源:origin: wildfly/wildfly

  1. public SocketAddress getLocalAddress() {
  2. return serverChannel.socket().getLocalSocketAddress();
  3. }

代码示例来源:origin: apache/zookeeper

  1. public LearnerCnxAcceptor() {
  2. super("LearnerCnxAcceptor-" + ss.getLocalSocketAddress(), zk
  3. .getZooKeeperServerListener());
  4. }

代码示例来源:origin: hierynomus/sshj

  1. /**
  2. * Close the ServerSocket that's listening for connections to forward.
  3. *
  4. * @throws IOException
  5. */
  6. public void close() throws IOException {
  7. if (!serverSocket.isClosed()) {
  8. log.info("Closing listener on {}", serverSocket.getLocalSocketAddress());
  9. runningThread.interrupt();
  10. serverSocket.close();
  11. }
  12. }

代码示例来源:origin: wildfly/wildfly

  1. protected PhysicalAddress getPhysicalAddress() {
  2. return new IpAddress((InetSocketAddress)srv_sock.getLocalSocketAddress());
  3. }

代码示例来源:origin: apache/geode

  1. @Override
  2. public String getServerName() {
  3. String name = this.serverSock.getLocalSocketAddress().toString();
  4. try {
  5. name = SocketCreator.getLocalHost().getCanonicalHostName() + "-" + name;
  6. } catch (Exception e) {
  7. }
  8. return name;
  9. }

代码示例来源:origin: wildfly/wildfly

  1. private String getAddress() {
  2. InetSocketAddress saddr=(InetSocketAddress)srv_sock.getLocalSocketAddress();
  3. InetAddress tmp=saddr.getAddress();
  4. if(!tmp.isAnyLocalAddress())
  5. return tmp.getHostAddress() + ":" + srv_sock.getLocalPort();
  6. for(Util.AddressScope scope: Util.AddressScope.values()) {
  7. try {
  8. InetAddress addr=Util.getAddress(scope);
  9. if(addr != null) return addr.getHostAddress() + ":" + srv_sock.getLocalPort();
  10. }
  11. catch(SocketException e) {
  12. }
  13. }
  14. return null;
  15. }

代码示例来源:origin: apache/zookeeper

  1. static Socket[] getSocketPair() throws IOException {
  2. ServerSocket ss =
  3. new ServerSocket(0, 50, InetAddress.getByName("127.0.0.1"));
  4. InetSocketAddress endPoint = (InetSocketAddress) ss.getLocalSocketAddress();
  5. Socket s = new Socket(endPoint.getAddress(), endPoint.getPort());
  6. return new Socket[] { s, ss.accept() };
  7. }
  8. static void readPacketSkippingPing(InputArchive ia, QuorumPacket qp) throws IOException {

代码示例来源:origin: voldemort/voldemort

  1. public NonRespondingSocketService(int port) throws IOException {
  2. // server socket with single element backlog queue (1) and dynamically
  3. // allocated port (0)
  4. serverSocket = new ServerSocket(port, 1);
  5. // just get the allocated port
  6. port = serverSocket.getLocalPort();
  7. // fill backlog queue by this request so consequent requests will be
  8. // blocked
  9. new Socket().connect(serverSocket.getLocalSocketAddress());
  10. }

代码示例来源:origin: k9mail/k-9

  1. public void start() throws IOException {
  2. checkServerNotRunning();
  3. InetAddress localAddress = InetAddress.getByName(null);
  4. ServerSocket serverSocket = new ServerSocket(0, 1, localAddress);
  5. InetSocketAddress localSocketAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
  6. host = localSocketAddress.getHostString();
  7. port = serverSocket.getLocalPort();
  8. mockServerThread = new MockServerThread(serverSocket, interactions, waitForConnectionClosed,
  9. waitForAllExpectedCommands, logger, keyStoreProvider);
  10. mockServerThread.start();
  11. }

代码示例来源:origin: k9mail/k-9

  1. public void start() throws IOException {
  2. checkServerNotRunning();
  3. InetAddress localAddress = InetAddress.getByName(null);
  4. ServerSocket serverSocket = new ServerSocket(0, 1, localAddress);
  5. InetSocketAddress localSocketAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
  6. host = localSocketAddress.getHostString();
  7. port = serverSocket.getLocalPort();
  8. mockServerThread = new MockServerThread(serverSocket, interactions, waitForConnectionClosed,
  9. waitForAllExpectedCommands, logger, keyStoreProvider);
  10. mockServerThread.start();
  11. }

代码示例来源:origin: k9mail/k-9

  1. public void start() throws IOException {
  2. checkServerNotRunning();
  3. InetAddress localAddress = InetAddress.getByName(null);
  4. ServerSocket serverSocket = new ServerSocket(0, 1, localAddress);
  5. InetSocketAddress localSocketAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
  6. host = localSocketAddress.getHostString();
  7. port = serverSocket.getLocalPort();
  8. mockServerThread = new MockServerThread(serverSocket, interactions, waitForConnectionClosed,
  9. waitForAllExpectedCommands, logger, keyStoreProvider);
  10. mockServerThread.start();
  11. }

代码示例来源:origin: wildfly/wildfly

  1. public void start() throws Exception {
  2. super.start();
  3. srv_sock=Util.createServerSocket(getSocketFactory(), "jgroups.stomp.srv_sock", bind_addr, port, port+50);
  4. if(log.isDebugEnabled())
  5. log.debug("server socket listening on " + srv_sock.getLocalSocketAddress());
  6. if(acceptor == null) {
  7. acceptor=getThreadFactory().newThread(this, "STOMP acceptor");
  8. acceptor.setDaemon(true);
  9. acceptor.start();
  10. }
  11. endpoint=endpoint_addr != null? endpoint_addr : getAddress();
  12. }

相关文章