io.netty.channel.socket.SocketChannel.localAddress()方法的使用及代码示例

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

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

SocketChannel.localAddress介绍

暂无

代码示例

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

@Override
protected CC initRemoteConnection(SocketChannel channel){
 local=channel.localAddress();
 remote=channel.remoteAddress();
 return null;
}

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

@Override
protected SC initRemoteConnection(SocketChannel channel) {
 local = channel.localAddress();
 remote = channel.remoteAddress();
 return null;
}

代码示例来源:origin: aadnk/ProtocolLib

@Override
public SocketAddress getLocalSocketAddress() {
  return ch.localAddress();
}

代码示例来源:origin: aadnk/ProtocolLib

@Override
public boolean isBound() {
  return ch.localAddress() != null;
}

代码示例来源:origin: aadnk/ProtocolLib

@Override
public int getLocalPort() {
  return ch.localAddress().getPort();
}

代码示例来源:origin: aadnk/ProtocolLib

@Override
public InetAddress getLocalAddress() {
  return ch.localAddress().getAddress();
}

代码示例来源:origin: dremio/dremio-oss

public String getName() {
 if (name == null) {
  name = String.format("%s <--> %s (%s)", channel.localAddress(), channel.remoteAddress(), clientName);
 }
 return name;
}

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

private int channel2Id(SocketChannel c) {
  return c.localAddress().getPort() + c.remoteAddress().getPort();
}

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

/**
 * Retrieve the connection information from the current connection directly
 * @param c the current channel
 * @return the connection information
 */
static ConnectionInfo newConnectionInfo(Channel c) {
  SocketChannel channel = (SocketChannel) c; 
  InetSocketAddress hostAddress = channel.localAddress();
  InetSocketAddress remoteAddress = channel.remoteAddress();
  String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http";
  return new ConnectionInfo(hostAddress, remoteAddress, scheme);
}

代码示例来源:origin: io.projectreactor.netty/reactor-netty

/**
 * Retrieve the connection information from the current connection directly
 * @param c the current channel
 * @return the connection information
 */
static ConnectionInfo newConnectionInfo(Channel c) {
  SocketChannel channel = (SocketChannel) c; 
  InetSocketAddress hostAddress = channel.localAddress();
  InetSocketAddress remoteAddress = channel.remoteAddress();
  String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http";
  return new ConnectionInfo(hostAddress, remoteAddress, scheme);
}

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

static ConnectionInfo parseForwardedInfo(HttpRequest request, SocketChannel channel) {
  InetSocketAddress hostAddress = channel.localAddress();
  InetSocketAddress remoteAddress = channel.remoteAddress();
  String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http";
  String forwarded = request.headers().get(FORWARDED_HEADER).split(",")[0];
  Matcher hostMatcher = FORWARDED_HOST_PATTERN.matcher(forwarded);
  if (hostMatcher.find()) {
    hostAddress = parseAddress(hostMatcher.group(1), hostAddress.getPort());
  }
  Matcher protoMatcher = FORWARDED_PROTO_PATTERN.matcher(forwarded);
  if (protoMatcher.find()) {
    scheme = protoMatcher.group(1).trim();
  }
  Matcher forMatcher = FORWARDED_FOR_PATTERN.matcher(forwarded);
  if(forMatcher.find()) {
    remoteAddress = parseAddress(forMatcher.group(1).trim(), remoteAddress.getPort());
  }
  return new ConnectionInfo(hostAddress, remoteAddress, scheme);
}

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

static ConnectionInfo parseXForwardedInfo(HttpRequest request, SocketChannel channel) {
  InetSocketAddress hostAddress = channel.localAddress();
  InetSocketAddress remoteAddress = channel.remoteAddress();
  String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http";
  if (request.headers().contains(XFORWARDED_IP_HEADER)) {
    String remoteIpValue = request.headers().get(XFORWARDED_IP_HEADER).split(",")[0];
    remoteAddress = parseAddress(remoteIpValue, remoteAddress.getPort());
  }
  if(request.headers().contains(XFORWARDED_HOST_HEADER)) {
    if(request.headers().contains(XFORWARDED_PORT_HEADER)) {
      hostAddress = InetSocketAddressUtil.createUnresolved(
          request.headers().get(XFORWARDED_HOST_HEADER).split(",")[0].trim(),
          Integer.parseInt(request.headers().get(XFORWARDED_PORT_HEADER).split(",")[0].trim()));
    }
    else {
      hostAddress = InetSocketAddressUtil.createUnresolved(
          request.headers().get(XFORWARDED_HOST_HEADER).split(",")[0].trim(),
          channel.localAddress().getPort());
    }
  }
  if (request.headers().contains(XFORWARDED_PROTO_HEADER)) {
    scheme = request.headers().get(XFORWARDED_PROTO_HEADER).trim();
  }
  return new ConnectionInfo(hostAddress, remoteAddress, scheme);
}

代码示例来源:origin: org.opennms.features.telemetry.listeners/org.opennms.features.telemetry.listeners.flow

@Override
  protected void initChannel(final SocketChannel ch) {
    final Session session = new TcpSession();
    ch.pipeline()
        .addLast(new TcpPacketDecoder(ch.remoteAddress(), ch.localAddress(), session))
        .addLast(new PacketHandler(Protocol.IPFIX, TcpListener.this.dispatcher))
        .addLast(new ChannelInboundHandlerAdapter() {
          @Override
          public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
            cause.printStackTrace();
            LOG.warn("Invalid packet: {}", cause.getMessage());
            LOG.debug("", cause);
            ctx.close();
          }
        });
  }
})

代码示例来源:origin: io.projectreactor.ipc/reactor-netty

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof HttpRequest) {
    final HttpRequest request = (HttpRequest) msg;
    accessLog = new AccessLog()
        .address(((SocketChannel) ctx.channel()).remoteAddress().getHostString())
        .port(((SocketChannel) ctx.channel()).localAddress().getPort())
        .method(request.method().name())
        .uri(request.uri())
        .protocol(request.protocolVersion().text());
  }
  super.channelRead(ctx, msg);
}

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

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof Http2HeadersFrame){
    final Http2HeadersFrame requestHeaders = (Http2HeadersFrame) msg;
    final SocketChannel channel = (SocketChannel) ctx.channel()
                             .parent();
    final Http2Headers headers = requestHeaders.headers();
    accessLog = new AccessLog()
        .address(channel.remoteAddress().getHostString())
        .port(channel.localAddress().getPort())
        .method(headers.method())
        .uri(headers.path())
        .protocol(H2_PROTOCOL_NAME);
  }
  super.channelRead(ctx, msg);
}

代码示例来源:origin: io.projectreactor.netty/reactor-netty

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof HttpRequest) {
    final HttpRequest request = (HttpRequest) msg;
    final SocketChannel channel = (SocketChannel) ctx.channel();
    accessLog = new AccessLog()
        .address(channel.remoteAddress().getHostString())
        .port(channel.localAddress().getPort())
        .method(request.method().name())
        .uri(request.uri())
        .protocol(request.protocolVersion().text());
  }
  super.channelRead(ctx, msg);
}

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

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof HttpRequest) {
    final HttpRequest request = (HttpRequest) msg;
    final SocketChannel channel = (SocketChannel) ctx.channel();
    accessLog = new AccessLog()
        .address(channel.remoteAddress().getHostString())
        .port(channel.localAddress().getPort())
        .method(request.method().name())
        .uri(request.uri())
        .protocol(request.protocolVersion().text());
  }
  super.channelRead(ctx, msg);
}

代码示例来源:origin: io.projectreactor.netty/reactor-netty

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  if (msg instanceof Http2HeadersFrame){
    final Http2HeadersFrame requestHeaders = (Http2HeadersFrame) msg;
    final SocketChannel channel = (SocketChannel) ctx.channel()
                             .parent();
    final Http2Headers headers = requestHeaders.headers();
    accessLog = new AccessLog()
        .address(channel.remoteAddress().getHostString())
        .port(channel.localAddress().getPort())
        .method(headers.method())
        .uri(headers.path())
        .protocol(H2_PROTOCOL_NAME);
  }
  super.channelRead(ctx, msg);
}

代码示例来源:origin: org.neo4j/neo4j-causal-clustering

@Override
protected void initChannel( SocketChannel channel ) throws Exception
{
  HandshakeClient handshakeClient = new HandshakeClient();
  installHandlers( channel, handshakeClient );
  log.info( "Scheduling handshake (and timeout) local %s remote %s", channel.localAddress(), channel.remoteAddress() );
  scheduleHandshake( channel, handshakeClient, handshakeDelay.newTimeout() );
  scheduleTimeout( channel, handshakeClient );
}

代码示例来源:origin: org.neo4j/neo4j-causal-clustering

@Override
public void initChannel( SocketChannel ch ) throws Exception
{
  log.info( "Installing handshake server local %s remote %s", ch.localAddress(), ch.remoteAddress() );
  pipelineBuilderFactory.server( ch, log )
      .addFraming()
      .add( "handshake_server_encoder", new ServerMessageEncoder() )
      .add( "handshake_server_decoder", new ServerMessageDecoder() )
      .add( "handshake_server", createHandshakeServer( ch ) )
      .install();
}

相关文章