비동기 소켓 채널
비동기 소켓 채널 (AsynchronousSocketChannel)
비동기적으로 연결하고 데이터를 전송하는 스트림 지향 연결 소켓 채널이에요. 비동기 읽기·쓰기와 연결을 지원합니다.
본문
AsynchronousSocketChannel은 비동기적으로 연결하고 데이터를 전송하는 스트림 지향 소켓 채널이에요.
public abstract class AsynchronousSocketChannel extends Object
implements AsynchronousByteChannel, NetworkChannel
채널은 open() 정적 메서드로 만듭니다.
public static AsynchronousSocketChannel open() throws IOException
public static AsynchronousSocketChannel open(ProtocolFamily family) throws IOException
public static AsynchronousSocketChannel open(AsynchronousChannelGroup group) throws IOException
연결은 비동기적으로 이뤄져요.
<A> void connect(SocketAddress remote, A attachment,
CompletionHandler<Void, ? super A> handler)
Future<Void> connect(SocketAddress remote)
데이터 전송은 AsynchronousByteChannel의 read/write를 사용하며, 완료 핸들러 방식과 Future 방식을 모두 지원해요.
<A> void read(ByteBuffer dst, A attachment, CompletionHandler<Integer, ? super A> handler)
<A> void write(ByteBuffer src, A attachment, CompletionHandler<Integer, ? super A> handler)
또한 shutdownInput()과 shutdownOutput()으로 입력·출력 방향을 비동기적으로 종료할 수 있어요. 이 채널은 채널 그룹의 스레드 풀에서 운영되며, 네트워크 지향 비동기 I/O의 핵심 클래스입니다.