Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

java - Netty connect() throwing io.netty.channel.AbstractChannel$AnnotatedSocketException: Invalid argument exception

This is the portion of the sample code I wrote

b = new Bootstrap();
        var remote = new InetSocketAddress("www.google.com", 8080);
        b.group(group)
                .channel(NioDatagramChannel.class)
                .handler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel channel) throws Exception {
                        channel.pipeline().addLast(new MyHandler());
                    }
                });
        var cf = b.connect(remote, new InetSocketAddress(8536)).sync(); // this line throws Exception

This is the Exception printed in the terminal

io.netty.channel.AbstractChannel$AnnotatedSocketException: Invalid argument: www.google.com/172.217.194.105:48830

Is there a reason for this error? What's the fix?

Full stacktrace

io.netty.channel.AbstractChannel$AnnotatedSocketException: Invalid argument: www.google.com/172.217.194.105:48830
Caused by: java.net.SocketException: Invalid argument
        at java.base/sun.nio.ch.Net.connect0(Native Method)
        at java.base/sun.nio.ch.Net.connect(Net.java:476)
        at java.base/sun.nio.ch.DatagramChannelImpl.connect(DatagramChannelImpl.java:848)
        at io.netty.channel.socket.nio.NioDatagramChannel.doConnect(NioDatagramChannel.java:215)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.connect(AbstractNioChannel.java:248)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.connect(DefaultChannelPipeline.java:1342)
        at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:548)
        at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:533)
        at io.netty.channel.DefaultChannelPipeline.connect(DefaultChannelPipeline.java:984)
        at io.netty.channel.AbstractChannel.connect(AbstractChannel.java:258)
        at io.netty.bootstrap.Bootstrap$3.run(Bootstrap.java:252)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:834)
question from:https://stackoverflow.com/questions/65645853/netty-connect-throwing-io-netty-channel-abstractchannelannotatedsocketexcepti

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use:

 b.connect(remote, new InetSocketAddress("127.0.0.1",8536)).sync() 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...