添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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)
                just a guess (as the exception is thrown from the JDK itself)... Can you ensure you bind to an ip4 address?  b.connect(remote, new InetSocketAddress("127.0.0.1",8536)).sync()
– Norman Maurer
                Jan 12, 2021 at 16:49
                @NormanMaurer b.connect(remote, new InetSocketAddress("127.0.0.1",8536)).sync()  this works without any issue
– MOHAMED SABTHAR
                Jan 13, 2021 at 11:24
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.