셀렉터 생성
try{
Selector selector = Selector.open();
}catch(IOException e){}
서버소켓채널 넌블로킹 설정
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.configureBlocking(false);
소켓채널 넌블로킹 설정
SocketChannel socketChannel = socketChannel.open();
socketChannel.configureBlocking(false);
셀렉터 등록
SelectionKey selectionKey = serverSocketCannel.register(selection,SelectionKey.OP_ACCEPT);
SelectionKey selectionKey = socketCannel.register(selection,SelectionKey.OP_CONNECT);
SelectionKey selectionKey = socketCannel.register(selection,SelectionKey.OP_READ);
SelectionKey selectionKey = socketCannel.register(selection,SelectionKey.OP_WRITE);
register()가 리턴한 selectionKey는 작업 유형 변경, 첨부 객체 저장, 채널등록 취소 등을 할 때 사용된다.
SelectionKey.OP_ACCEPT - 클라이언트 연결 수락 작업
SelectionKey.OP_CONNECT - 서버 연결 요청 작업
SelectionKey.OP_READ - 읽기 작업
SelectionKey.OP_WRITE - 쓰기 작업
등록된 셀렉터 재등록
SelectionKey key = socketChannel.keyFor(selector);
2017/01/05 - [코딩/Java] - [NIO]TCP 넌블로킹 채널?
'코딩 > Java' 카테고리의 다른 글
[NIO]TCP 비동기 채널 - 비동기 소켓 채널 (0) | 2017.01.05 |
---|---|
[NIO]TCP 비동기 채널 - 비동기 서버소켓 채널 (0) | 2017.01.05 |
[NIO]TCP 비동기 채널? (0) | 2017.01.05 |
[NIO]TCP 넌블로킹 채널 - 선택된 키셋 (0) | 2017.01.05 |
[NIO]TCP 넌블로킹 채널? (0) | 2017.01.05 |