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


Java SocketAddress.toString方法代码示例

本文整理汇总了Java中java.net.SocketAddress.toString方法的典型用法代码示例。如果您正苦于以下问题:Java SocketAddress.toString方法的具体用法?Java SocketAddress.toString怎么用?Java SocketAddress.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.SocketAddress的用法示例。


在下文中一共展示了SocketAddress.toString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseChannelRemoteAddr

import java.net.SocketAddress; //导入方法依赖的package包/类
public static String parseChannelRemoteAddr(final Channel channel) {
    if (null == channel) {
        return "";
    }
    final SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
        int index = addr.lastIndexOf("/");
        if (index >= 0) {
            return addr.substring(index + 1);
        }

        return addr;
    }

    return "";
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:19,代码来源:RemotingHelper.java

示例2: addressToString

import java.net.SocketAddress; //导入方法依赖的package包/类
private String addressToString(SocketAddress address)
{
    String s = address.toString();

    if (s.contains("/"))
    {
        s = s.substring(s.indexOf(47) + 1);
    }

    if (s.contains(":"))
    {
        s = s.substring(0, s.indexOf(58));
    }

    return s;
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:17,代码来源:UserListIPBans.java

示例3: parseChannelRemoteAddr

import java.net.SocketAddress; //导入方法依赖的package包/类
/**
 * 获取Channel的远程IP地址
 * @param channel
 * @return
 */
public static String parseChannelRemoteAddr(final Channel channel) {
    if (null == channel) {
        return "";
    }
    SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
        int index = addr.lastIndexOf("/");
        if (index >= 0) {
            return addr.substring(index + 1);
        }

        return addr;
    }

    return "";
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:24,代码来源:NettyUtil.java

示例4: parseRemoteAddr

import java.net.SocketAddress; //导入方法依赖的package包/类
/**
 * 获取Channel的远程IP地址
 * @param channel
 * @return
 */
public static String parseRemoteAddr(final Channel channel) {
    if (null == channel) {
        return "";
    }
    SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
        int index = addr.lastIndexOf("/");
        if (index >= 0) {
            return addr.substring(index + 1);
        }

        return addr;
    }

    return "";
}
 
开发者ID:beyondfengyu,项目名称:DistributedID,代码行数:24,代码来源:NettyUtil.java

示例5: parseChannelRemoteAddr

import java.net.SocketAddress; //导入方法依赖的package包/类
public static String parseChannelRemoteAddr(final Channel channel) {
    if (null == channel) {
        return "";
    }
    SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
        int index = addr.lastIndexOf("/");
        if (index >= 0) {
            return addr.substring(index + 1);
        }

        return addr;
    }

    return "";
}
 
开发者ID:beyondfengyu,项目名称:ConfigCenter,代码行数:19,代码来源:RemotingHelper.java

示例6: connect

import java.net.SocketAddress; //导入方法依赖的package包/类
protected void connect(SocketAddress remoteAddr, int timeout) throws IOException {
    if(remoteAddr instanceof InetSocketAddress) {
        InetSocketAddress e = (InetSocketAddress)remoteAddr;
        this.name = e.getHostName();
        this.setProtocolFromPort(e.getPort());
    } else {
        this.name = remoteAddr.toString();
    }
    Logger.d("Socket connect", this.name);

    try {
        this.delegator.invoke(new Object[]{remoteAddr, Integer.valueOf(timeout)});
    } catch (Exception var6) {
        Exception e1 = var6;
        if(var6 instanceof IOException) {
            throw (IOException)var6;
        }
        try {
            throw e1.getCause();
        } catch (Throwable var5) {
            var5.printStackTrace();
        }
    }

    this.startTime = System.currentTimeMillis();
}
 
开发者ID:TeamThresh,项目名称:Lantern-sdk,代码行数:27,代码来源:LanternSocketImpl.java

示例7: parseSocketAddressAddr

import java.net.SocketAddress; //导入方法依赖的package包/类
public static String parseSocketAddressAddr(SocketAddress socketAddress) {
    if (socketAddress != null) {
        final String addr = socketAddress.toString();

        if (addr.length() > 0) {
            return addr.substring(1);
        }
    }
    return "";
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:11,代码来源:RemotingHelper.java

示例8: getStatistics

import java.net.SocketAddress; //导入方法依赖的package包/类
/**
 * Get cache statistics for all memcached hosts known to {@link MemcachedClientIF}.
 *
 * @return Statistics for all available hosts.
 */
@Override
protected CacheStatistics[] getStatistics() {


    final Map<SocketAddress, Map<String, String>> allStats = memcachedClient.getStats();
    final List<CacheStatistics> statsList = new ArrayList<>();
    for (final Map.Entry<SocketAddress, Map<String, String>> entry : allStats.entrySet()) {
        final SocketAddress key = entry.getKey();
        final Map<String, String> statsMap = entry.getValue();

        if (!statsMap.isEmpty()) {
            final long size = Long.parseLong(statsMap.get("bytes"));
            final long capacity = Long.parseLong(statsMap.get("limit_maxbytes"));
            final long evictions = Long.parseLong(statsMap.get("evictions"));

            final String name;
            if (key instanceof InetSocketAddress) {
                name = ((InetSocketAddress) key).getHostName();
            } else {
                name = key.toString();
            }
            statsList.add(new SimpleCacheStatistics(size, capacity, evictions, name));
        }
    }
    return statsList.toArray(new CacheStatistics[statsList.size()]);
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:32,代码来源:MemcachedMonitor.java

示例9: connect

import java.net.SocketAddress; //导入方法依赖的package包/类
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise)
        throws Exception {
    final String local = localAddress == null ? "UNKNOW" : localAddress.toString();
    final String remote = remoteAddress == null ? "UNKNOW" : remoteAddress.toString();
    log.info("NETTY CLIENT PIPELINE: CONNECT  {} => {}", local, remote);
    super.connect(ctx, remoteAddress, localAddress, promise);

    if (NettyRemotingClient.this.channelEventListener != null) {
        NettyRemotingClient.this.putNettyEvent(new NettyEvent(NettyEventType.CONNECT, remoteAddress.toString(), ctx.channel()));
    }
}
 
开发者ID:beyondfengyu,项目名称:ConfigCenter,代码行数:13,代码来源:NettyRemotingClient.java

示例10: testDeleteConnections

import java.net.SocketAddress; //导入方法依赖的package包/类
@Test
public void testDeleteConnections() throws Exception {
  Collection<BoundDataCenter> datacenters = server.getCluster().getDataCenters();
  BoundDataCenter dc = datacenters.iterator().next();
  Iterator<BoundNode> nodeIterator = dc.getNodes().iterator();
  BoundNode node = nodeIterator.next();

  ArrayList<Scope> list = new ArrayList<>();
  list.add(new Scope(server.getCluster().getId(), dc.getId(), node.getId()));
  list.add(new Scope(server.getCluster().getId(), dc.getId(), null));
  list.add(new Scope(server.getCluster().getId(), null, null));

  for (Scope scope : list) {
    try (com.datastax.driver.core.Cluster driverCluster =
        defaultBuilder()
            .addContactPointsWithPorts((InetSocketAddress) node.getAddress())
            .build()) {
      driverCluster.init();
      HttpTestResponse responseDelete =
          server.delete("/connections/" + scope.toString() + "?type=disconnect");

      ClusterConnectionReport responseReport =
          om.readValue(responseDelete.body, ClusterConnectionReport.class);
      Collection<NodeConnectionReport> nodes =
          getNodeConnectionReports(responseReport, dc.getId());

      assertThat(responseDelete.response.statusCode()).isEqualTo(200);

      HttpTestResponse responseNewConnections = server.get("/connections/" + scope.toString());
      assertThat(responseNewConnections.body).isNotEqualTo(responseDelete.body);
      for (NodeConnectionReport nodeReport : nodes) {
        for (SocketAddress sA : nodeReport.getConnections()) {
          String sAString = sA.toString();
          assertThat(responseDelete.body).contains(sAString.substring(1, sAString.length()));
          assertThat(responseNewConnections.body)
              .doesNotContain(sAString.substring(1, sAString.length()));
        }
      }
    }
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:42,代码来源:EndpointIntegrationTest.java

示例11: readClientVersion

import java.net.SocketAddress; //导入方法依赖的package包/类
private static Version readClientVersion(ServerConnection connection)
    throws IOException, VersionException {

  Socket socket = connection.getSocket();
  int timeout = connection.getHandShakeTimeout();

  int soTimeout = -1;
  try {
    soTimeout = socket.getSoTimeout();
    socket.setSoTimeout(timeout);
    InputStream is = socket.getInputStream();
    short clientVersionOrdinal = Version.readOrdinalFromInputStream(is);
    if (clientVersionOrdinal == -1) {
      throw new EOFException(
          LocalizedStrings.ServerHandShakeProcessor_HANDSHAKEREADER_EOF_REACHED_BEFORE_CLIENT_VERSION_COULD_BE_READ
              .toLocalizedString());
    }
    Version clientVersion = null;
    try {
      clientVersion = Version.fromOrdinal(clientVersionOrdinal, true);
    } catch (UnsupportedVersionException uve) {
      // Allows higher version of wan site to connect to server
      if (connection.getCommunicationMode() == Acceptor.GATEWAY_TO_GATEWAY
          && !(clientVersionOrdinal == Version.NOT_SUPPORTED_ORDINAL)) {
        return Acceptor.VERSION;
      } else {
        SocketAddress sa = socket.getRemoteSocketAddress();
        String sInfo = "";
        if (sa != null) {
          sInfo = " Client: " + sa.toString() + ".";
        }
        throw new UnsupportedVersionException(uve.getMessage() + sInfo);
      }
    }

    if (!clientVersion.compatibleWith(Acceptor.VERSION)) {
      throw new IncompatibleVersionException(clientVersion, Acceptor.VERSION);// we can throw this
                                                                              // to restrict
    } // Backward Compatibilty Support to limited no of versions
    return clientVersion;
  } finally {
    if (soTimeout != -1) {
      try {
        socket.setSoTimeout(soTimeout);
      } catch (IOException ignore) {
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:50,代码来源:ServerHandShakeProcessor.java


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