当我尝试使用 IPv4 地址创建套接字时,它是成功的,但是当我尝试使用 IPv6 地址和端口号创建套接字时,它会引发异常:
java.net.SocketException: Network is unreachable: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at epcs.intf.be.SimConnectionHandler.connect(SimConnectionHandler.java:332)
at epcs.intf.be.BackEndConnection.connect(BackEndConnection.java:42)
at epcs.intf.be.ProcedureRunner.runScenario(ProcedureRunner.java:230)
at epcs.exec.Runner.SendExecTrigger(Runner.java:418)
at epcs.exec.Runner.sendCommand(Runner.java:454)
at epcs.main.ExecutionThread$TaskStartTestCaseExecution.run(ExecutionThread.java:98)
at epcs.main.ExecutionThread.run(ExecutionThread.java:29)
代码:
我正在 Windows 机器上通过 Eclipse IDE 运行代码。
if(p_objSimData.getIpAddress().contains(":") )
{
System.out.println("IPV6 Address Found\n");
InetAddress ip6addr = Inet6Address.getByName(p_objSimData.getIpAddress());
System.out.println("InetAddress ip6addr = "+ip6addr); **//prints //2011::11 - IPv6 address**
objConnection.m_objSocket = new Socket(ip6addr,p_objSimData.getPortNo()); - **here it is throwing an exception**
}
else
{
objConnection.m_objSocket = new Socket(p_objSimData.getIpAddress(),p_objSimData.getPortNo());
//m_hmObjConnection1.put(p_objSimData.getIpAddress(), objConnection.m_objSocket);
m_hmObjConnection1.put(p_objSimData.getIpPort(), objConnection.m_objSocket);
}