비동기 서버 소켓 채널
비동기 서버 소켓 채널 (AsynchronousServerSocketChannel)
비동기적으로 연결을 수락하는 스트림 지향 리스닝 소켓 채널이에요. 클라이언트 연결을 비동기 accept로 받습니다.
본문
AsynchronousServerSocketChannel은 비동기적으로 연결을 수락하는 리스닝 소켓 채널이에요.
public abstract class AsynchronousServerSocketChannel extends Object
implements AsynchronousChannel, NetworkChannel
채널은 open() 정적 메서드로 만들 수 있어요. 매개변수 없는 open()은 인터넷 프로토콜 소켓용이고, open(ProtocolFamily)은 지정된 프로토콜 패밀리용입니다.
public static AsynchronousServerSocketChannel open() throws IOException
public static AsynchronousServerSocketChannel open(ProtocolFamily family) throws IOException
소켓 옵션은 setOption()으로 설정하고, 바인딩은 bind()로 로컬 주소에 합니다. 클라이언트 연결은 accept()로 비동기적으로 수락해요.
<A> void accept(A attachment, CompletionHandler<AsynchronousSocketChannel, ? super A> handler)
Future<AsynchronousSocketChannel> accept()
완료 핸들러 버전은 연결이 수락되면 핸들러를 호출하고, Future 버전은 Future.get()으로 결과를 기다립니다. 비동기이므로 하나의 accept 작업이 진행 중일 때 다른 accept를 시도하면 AcceptPendingException이 던져질 수 있어요. AsynchronousChannelGroup에 바인딩할 수도 있습니다.