Java Code Examples for io.netty.channel.Channel#remoteAddress()
The following examples show how to use
io.netty.channel.Channel#remoteAddress() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RemotingHelper.java From dts with Apache License 2.0 | 6 votes |
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 ""; }
Example 2
Source File: NettyUtil.java From netty-chat with Apache License 2.0 | 6 votes |
/** * 获取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 ""; }
Example 3
Source File: IPUtils.java From timer with Apache License 2.0 | 6 votes |
public static String parseChannelRemoteAddr1(Channel channel) { if(channel == null){ logger.info("channel is null"); return ""; } SocketAddress socketAddress = channel.remoteAddress(); if (socketAddress == null) { logger.info("socketAddress is null"); return ""; } if (socketAddress instanceof InetSocketAddress) { InetSocketAddress addr = (InetSocketAddress)socketAddress; String remoteHostAddr = addr.getAddress().getHostAddress(); int remoteHostPort = addr.getPort(); return remoteHostAddr + ":" + remoteHostPort; } else { logger.info("RemoteAddress is not InetSocketAddress"); return parseChannelRemoteAddr(channel); } }
Example 4
Source File: RemotingHelper.java From rocketmq-read with Apache License 2.0 | 6 votes |
/** * 从Channel中获取远程连接地址 * @param channel 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 ""; }
Example 5
Source File: AbstractSession.java From socketio with Apache License 2.0 | 6 votes |
public AbstractSession( final Channel channel, final String sessionId, final String origin, final SessionDisconnectHandler disconnectHandler, final TransportType upgradedFromTransportType, final int localPort, final SocketAddress remoteAddress) { this.sessionId = sessionId; this.remoteAddress = remoteAddress == null ? channel.remoteAddress() : remoteAddress; this.origin = origin; this.localPort = localPort; this.disconnectHandler = disconnectHandler; this.upgradedFromTransportType = upgradedFromTransportType; heartbeatScheduler = new SocketIOHeartbeatScheduler(this); setState(State.CONNECTING); }
Example 6
Source File: RemotingHelper.java From jmqtt with Apache License 2.0 | 6 votes |
public static String getRemoteAddr(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 ""; }
Example 7
Source File: ChannelUtil.java From DDMQ with Apache License 2.0 | 5 votes |
public static String getRemoteIp(Channel channel) { InetSocketAddress inetSocketAddress = (InetSocketAddress) channel.remoteAddress(); if (inetSocketAddress == null) { return ""; } final InetAddress inetAddr = inetSocketAddress.getAddress(); return inetAddr != null ? inetAddr.getHostAddress() : inetSocketAddress.getHostName(); }
Example 8
Source File: ChannelUtil.java From rocketmq with Apache License 2.0 | 5 votes |
public static String getRemoteIp(Channel channel) { InetSocketAddress inetSocketAddress = (InetSocketAddress) channel.remoteAddress(); if (inetSocketAddress == null) { return ""; } final InetAddress inetAddr = inetSocketAddress.getAddress(); return inetAddr != null ? inetAddr.getHostAddress() : inetSocketAddress.getHostName(); }
Example 9
Source File: AbstractBounceHandler.java From arcusplatform with Apache License 2.0 | 5 votes |
@Nullable protected String getIp(Channel channel) { SocketAddress address = channel.remoteAddress(); if(address instanceof InetSocketAddress) { return ((InetSocketAddress) address).getAddress().getHostAddress(); } else { logger.warn("Non inet socket address from client: {}", address); return null; } }
Example 10
Source File: RemotingHelper.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
public static String parseChannelRemoteName(final Channel channel) { if (null == channel) { return ""; } final InetSocketAddress remote = (InetSocketAddress) channel.remoteAddress(); if (remote != null) { return remote.getAddress().getHostName(); } return ""; }
Example 11
Source File: RemotingUtil.java From eagle with Apache License 2.0 | 5 votes |
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 ""; }
Example 12
Source File: RemotingHelper.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
public static String parseChannelRemoteName(final Channel channel) { if (null == channel) { return ""; } final InetSocketAddress remote = (InetSocketAddress) channel.remoteAddress(); if (remote != null) { return remote.getAddress().getHostName(); } return ""; }
Example 13
Source File: HttpServerHandler.java From armeria with Apache License 2.0 | 5 votes |
private ProxiedAddresses determineProxiedAddresses(Channel channel, RequestHeaders headers) { final InetSocketAddress remoteAddress = (InetSocketAddress) channel.remoteAddress(); if (config.clientAddressTrustedProxyFilter().test(remoteAddress.getAddress())) { return HttpHeaderUtil.determineProxiedAddresses( headers, config.clientAddressSources(), proxiedAddresses, remoteAddress, config.clientAddressFilter()); } else { return proxiedAddresses != null ? proxiedAddresses : ProxiedAddresses.of(remoteAddress); } }
Example 14
Source File: ConnectionPool.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Format to "ip:port". * * @param channel channel * @return formatted key */ private String getConnectionKey(Channel channel) { InetSocketAddress socketAddress = (InetSocketAddress)channel.remoteAddress(); String remoteIp = socketAddress.getAddress().getHostAddress(); int remotePort = socketAddress.getPort(); return remoteIp + ":" + remotePort; }
Example 15
Source File: NettyServerTransport.java From grpc-java with Apache License 2.0 | 5 votes |
NettyServerTransport( Channel channel, ChannelPromise channelUnused, ProtocolNegotiator protocolNegotiator, List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, int maxStreams, boolean autoFlowControl, int flowControlWindow, int maxMessageSize, int maxHeaderListSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos) { this.channel = Preconditions.checkNotNull(channel, "channel"); this.channelUnused = channelUnused; this.protocolNegotiator = Preconditions.checkNotNull(protocolNegotiator, "protocolNegotiator"); this.streamTracerFactories = Preconditions.checkNotNull(streamTracerFactories, "streamTracerFactories"); this.transportTracer = Preconditions.checkNotNull(transportTracer, "transportTracer"); this.maxStreams = maxStreams; this.autoFlowControl = autoFlowControl; this.flowControlWindow = flowControlWindow; this.maxMessageSize = maxMessageSize; this.maxHeaderListSize = maxHeaderListSize; this.keepAliveTimeInNanos = keepAliveTimeInNanos; this.keepAliveTimeoutInNanos = keepAliveTimeoutInNanos; this.maxConnectionIdleInNanos = maxConnectionIdleInNanos; this.maxConnectionAgeInNanos = maxConnectionAgeInNanos; this.maxConnectionAgeGraceInNanos = maxConnectionAgeGraceInNanos; this.permitKeepAliveWithoutCalls = permitKeepAliveWithoutCalls; this.permitKeepAliveTimeInNanos = permitKeepAliveTimeInNanos; SocketAddress remote = channel.remoteAddress(); this.logId = InternalLogId.allocate(getClass(), remote != null ? remote.toString() : null); }
Example 16
Source File: RemotingHelper.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
public static String parseChannelRemoteName(final Channel channel) { if (null == channel) { return ""; } final InetSocketAddress remote = (InetSocketAddress) channel.remoteAddress(); if (remote != null) { return remote.getAddress().getHostName(); } return ""; }
Example 17
Source File: RemotingHelper.java From rocketmq with Apache License 2.0 | 5 votes |
public static String parseChannelRemoteName(final Channel channel) { if (null == channel) { return ""; } final InetSocketAddress remote = (InetSocketAddress) channel.remoteAddress(); if (remote != null) { return remote.getAddress().getHostName(); } return ""; }
Example 18
Source File: NettyConnection.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
public NettyConnection(Channel channel, ConnectionPool pool) { this.channel = channel; this.pool = pool; InetSocketAddress socketAddress = (InetSocketAddress) channel.remoteAddress(); this.remoteIp = socketAddress.getAddress().getHostAddress(); this.remotePort = socketAddress.getPort(); this.lastReadTime = System.currentTimeMillis(); }
Example 19
Source File: ChannelUtil.java From rocketmq with Apache License 2.0 | 5 votes |
public static String getRemoteIp(Channel channel) { InetSocketAddress inetSocketAddress = (InetSocketAddress) channel.remoteAddress(); if (inetSocketAddress == null) { return ""; } final InetAddress inetAddr = inetSocketAddress.getAddress(); return (inetAddr != null ? inetAddr.getHostAddress() : inetSocketAddress.getHostName()); }
Example 20
Source File: HttpSessionHandler.java From armeria with Apache License 2.0 | 5 votes |
HttpSessionHandler(HttpChannelPool channelPool, Channel channel, Promise<Channel> sessionPromise, ScheduledFuture<?> sessionTimeoutFuture, MeterRegistry meterRegistry, boolean useHttp1Pipelining, long idleTimeoutMillis, long pingIntervalMillis, ProxyConfig proxyConfig) { this.channelPool = requireNonNull(channelPool, "channelPool"); this.channel = requireNonNull(channel, "channel"); remoteAddress = channel.remoteAddress(); this.sessionPromise = requireNonNull(sessionPromise, "sessionPromise"); this.sessionTimeoutFuture = requireNonNull(sessionTimeoutFuture, "sessionTimeoutFuture"); this.meterRegistry = meterRegistry; this.useHttp1Pipelining = useHttp1Pipelining; this.idleTimeoutMillis = idleTimeoutMillis; this.pingIntervalMillis = pingIntervalMillis; switch (proxyConfig.proxyType()) { case DIRECT: useProxyConnection = false; break; case SOCKS4: case SOCKS5: case CONNECT: useProxyConnection = true; break; default: throw new Error(); // Should never reach here. } }