ubuntu20.04 java读取opc服务端数据
1、前言
2、代码
OPC_ubuntu待优化.zip
OPC_ubuntu_java.zip
endpointUrl=opc.tcp://10.32.117.92:8098/TM.LongWallMind.OPCUAServer4.x
applicationUri=urn:eclipse:milo:bjlthy
3、报错
java.util.concurrent.ExecutionException: java.net.UnknownHostException: q-pc: 域名解析暂时失败
at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
at com.lthy.client.OPCUAClient.createConnection(OPCUAClient.java:136)
at com.lthy.OPC.main(OPC.java:31)
Caused by: java.net.UnknownHostException: q-pc: 域名解析暂时失败
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at java.net.InetAddress.getByName(InetAddress.java:1076)
4、解决
读取opc数据涉及到域名解析,在ubuntu的/etc/hosts文件中增加q-pc的域名解析