org.rx.net.shadowsocks.ServerSendHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxlib Show documentation
Show all versions of rxlib Show documentation
A set of utilities for Java
package org.rx.net.shadowsocks;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.channel.socket.DatagramPacket;
import java.net.InetSocketAddress;
@ChannelHandler.Sharable
public class ServerSendHandler extends ChannelOutboundHandlerAdapter {
public static final ServerSendHandler DEFAULT = new ServerSendHandler();
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
boolean isUdp = ctx.channel().attr(SSCommon.IS_UDP).get();
if (isUdp) {
ByteBuf buf = (ByteBuf) msg;
InetSocketAddress clientAddr = ctx.channel().attr(SSCommon.REMOTE_ADDRESS).get();
msg = new DatagramPacket(buf, clientAddr);
}
super.write(ctx, msg, promise);
}
}