简体   繁体   中英

netty bootstrap connection refused

trying to connect client io.netty.bootstrap.Bootstrap :

ChannelFuture cf = null;
cf = m_bootstrap.connect(new InetSocketAddress(InetAddress
            .getByName("127.0.0.1"), 8084));

in cf, result : java.net.ConnectException: Connection refused: /127.0.0.1:8084 detailed message:

[sun.nio.ch.SocketChannelImpl.checkConnect(Native Method), sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:599), io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:208), io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:287), io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528), io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468), io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382), io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354), io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116), java.lang.Thread.run(Thread.java:695)]

my /etc/hosts file looks like this:

127.0.0.1>--localhost
255.255.255.255>broadcasthost
::1             localhost-
****::1%lo*>localhost
127.0.0.1>--********

Not sure what to do? literally assumed I can pass localhost and port and it should work.

Are you sure there is something really listing on the port ?

Try:

telnet 127.0.0.1 8084

turns out in MAC since the server binds to my IP address and not localhost or 127.0.0.1 it would not accept the the client to connect to localhost/127.0.0.1. It worked fine when I replaced loopback addr with my IP. Strange but guess it is something to do with difference interfaces in MAC. Not sure how Windows would react.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM