我正在尝试使用异步通信模型创建服务器并希望绑定多个端口,但是当我调用一个以上的 bind 方法时,它会引发错误“AlreadyBoundException”。有没有办法做到这一点?这是我的代码
try(AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open()){
if(listener.isOpen()){
listener.setOption(StandardSocketOptions.SO_RCVBUF, 4*1024);
listener.setOption(StandardSocketOptions.SO_REUSEADDR, true);
listener.bind(new InetSocketAddress(9001));
listener.bind(new InetSocketAddress(9002));