简体   繁体   中英

Netty server remote connection

Netty server, Fedora. I just can't connect to the server from remote host and no listening socket is displayed via netstat util. However I can establish the connection running client and server on the same machine. That's simply like that:

port = System.getProperty(PORT_PROPERTY);
Preconditions.checkNotNull(port, "Network error, port property is not set");
hostAddress = new InetSocketAddress(Integer.valueOf(port));
...
serverChannel = bootstrap.bind(hostAddress);

I've tried initializing hostAddress with the port only, localhost IP, 0.0.0.0 IP, and IP of my network. Nothing helps. What could be the root of problem?

Here's some suggestions that should help disagnosing the problem:

  • For clarity (until you resolve this), stick to using

new InetSocketAddress("0.0.0.0", Integer.valueOf(port))

since this will ensure you bind to all interfaces.

  • Invoke the JVM with -Djava.net.preferIPv4Stack=true to force the JVM into IPV4. I have found it easier to muck with these issues when in IPV4 since is it less complicated than V6.

  • Get the PID of the JVM and then issue a netstat like this:

sudo netstat -ap --numeric-ports | grep <PID>

This should display all sockets for your JVM instance. (Please post this output if you're still not able to connect remotely. Also post the output of ifconfig )

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