Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline()
.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()))
.addLast(new StringDecoder())
.addLast(new StringEncoder())
.addLast(new NettyClientHandler(phone));
}
});
/* 소켓 연결 및 리스너 등록 */
b.connect(HOST, PORT)
.sync()
.addListener((ChannelFuture cf) -> {
clientList.add(phone); //연결된 클라이언트 리스트에 추가
}
});
--
이 메일은 Google 그룹스 'Netty Korean User Group' 그룹에 가입한 분들에게 전송되는 메시지입니다.
이 그룹에서 탈퇴하고 더 이상 이메일을 받지 않으려면 netty-ko+u...@googlegroups.com에 이메일을 보내세요.
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/netty-ko/60690dbb-23bc-428d-ac9c-8d47cdc48cd3n%40googlegroups.com을(를) 방문하세요.
EventLoopGroup group = new NioEventLoopGroup();
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/netty-ko/61984541-dec7-4c8b-8e0f-3203a809c576n%40googlegroups.com을(를) 방문하세요.
Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline()
.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()))
.addLast(new StringDecoder())
.addLast(new StringEncoder())
.addLast(new NettyClientHandler(phone));
}
});
위와같은 코드에서 EventLoopGroup은 스레드 풀이라고 생각하시면 되고,
Bootstrap 은 설정을 다루는 객체라고 생각하시면 됩니다.
그러므로, 클라이언트와의 연결마다 부트스트랩 객체를 생성할 이유는 특수한 경우가 아니면 거의 없을거 같고,
보통 channel 하나를 소켓하나라고 보기 때문에, 클라이언트 하나당 channel하나씩 이라고 이해하시면 좋을거라 생각합니다.
Bootstrap.connect함수를 호출해서, 반환되는 channel객체를 클라이언트마다 할당해서 사용하도록 로직을 변경해보시는 것을 추천드립니다.