package auth;
import auth.handler.AuthLogicConnectionHandler;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import protobuf.code.PacketDecoder;
import protobuf.code.PacketEncoder;
/**
* Created by win7 on 2016/3/5.
*/
public class AuthLogicConnection {
private static final Logger logger = LoggerFactory.getLogger(AuthLogicConnection.class);
public static void startAuthLogicConnection(String ip, int port) {
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap()
.group(group)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel channel)
throws Exception {
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast("MessageDecoder", new PacketDecoder());
pipeline.addLast("MessageEncoder", new PacketEncoder());
pipeline.addLast("AuthLogicConnectionHandler", new AuthLogicConnectionHandler()); //Auth -> gate
}
});
bootstrap.connect(ip, port);
}
}