创建一个ClientSocket程序如下:
String remote_host = "10.0.0.1";
int remote_port = 9990;
InetAddress address = InetAddress.getByName(remote_host);//It gets a Inet4Address
String bindhost="facade";
InetAddress bindaddress = InetAddress.getByName(bindhost);//It gets a Inet6Address as Ipv6 address is configured for hostname "facade" in /etc/hosts
socket = new Socket(address, remote_port,bindaddress,9787);
获取异常如下:
java.net.SocketException: Network is unreachable
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:276)
at Client.main(Client.java:25)
我们可以按上述方式创建套接字吗???
尝试使用类似方式的 ssh 协议。得到相同的错误:[root@mysystem ~]# ssh -6 -b facade root@10.0.0.1 ssh: connect to host 10.0.0.1 port 22: Network is unreachable
//facade在/etc/hosts中配置了ipv6地址