当前位置: 首页 > 知识库问答 >
问题:

使用Eclipse Milo连接到OPC-UA服务器在BadHostUnknown上失败

万喜
2023-03-14

我是OPC-UA和Eclipse Milo的新手,我正在尝试构建一个客户端,可以连接到我们刚刚购买的机器的OPC-UA服务器。

通过使用这个python教程系列,我已经能够在我的笔记本电脑上设置一个简单的OPC-UA服务器:https://www.youtube.com/watch?v=NbKeBfK3pfk.此外,我已经能够使用Eclipse Milo示例成功运行订阅示例,从该服务器读取一些值。

然而,我一直难以连接到我们刚刚收到的机器的OPC-UA服务器。我已经使用UaExpert客户端成功地连接到此服务器,但我们希望使用Eclipse Milo构建我们自己的客户端。我可以看到,当使用UaExpert连接到服务器时,出现了一些警告,这些警告似乎提供了有关问题的线索,但我在服务器-客户端通信/OPC-UA方面的经验太少,希望能得到一些帮助。我将解释使用UaExpert客户端时会发生什么,因为我一直在使用它来尝试和诊断正在发生的事情。

我注意到,当我第一次启动UaEA时,我收到了以下可能相关的错误:

Discovery FindServersOnNetwork on opc.tcp://localhost:4840 failed (BadTimeout), falling back to FindServers
Discovery FindServers on opc.tpc://localhost:4840 failed (BadTimeout)
Discovery GetEndpoints on opc.tcp://localhost:4840 failed

我对网络真的很陌生,所以不确定这到底意味着什么。

我将概述在尝试获取Eclipse Milo的SubscriptionExample与这台机器的服务器一起工作时所遵循的过程。首先,我将getEndpointUrl()方法更改为我们正在使用的设备的ip地址:return“opc”。tcp://11.23.1.1:4840“。我可以从笔记本电脑上使用ping 11.23.1.1成功ping设备。当我尝试使用此地址运行SubscriptionExample时,我收到以下错误:

[NonceUtilSecureRandom] INFO  o.e.m.o.stack.core.util.NonceUtil - SecureRandom seeded in 0ms.
18:36:23.879 [main] ERROR o.e.m.e.client.ClientExampleRunner - Error running client example: java.net.UnknownHostException: br-automation
java.util.concurrent.ExecutionException: java.net.UnknownHostException: br-automation
    at java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
    at java.util.concurrent.CompletableFuture.get(Unknown Source)
    at org.eclipse.milo.examples.client.SubscriptionExample.run(SubscriptionExample.java:50)
    at org.eclipse.milo.examples.client.ClientExampleRunner.run(ClientExampleRunner.java:120)
    at org.eclipse.milo.examples.client.SubscriptionExample.main(SubscriptionExample.java:42)
Caused by: java.net.UnknownHostException: br-automation
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)
    at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
    at java.net.InetAddress.getAllByName0(Unknown Source)
    at java.net.InetAddress.getAllByName(Unknown Source)
    at java.net.InetAddress.getAllByName(Unknown Source)
    at java.net.InetAddress.getByName(Unknown Source)
    at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:148)
    at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:145)
    at java.security.AccessController.doPrivileged(Native Method)
    at io.netty.util.internal.SocketUtils.addressByName(SocketUtils.java:145)
    at io.netty.resolver.DefaultNameResolver.doResolve(DefaultNameResolver.java:43)
    at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:63)
    at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:55)
    at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:57)
    at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:32)
    at io.netty.resolver.AbstractAddressResolver.resolve(AbstractAddressResolver.java:108)
    at io.netty.bootstrap.Bootstrap.doResolveAndConnect0(Bootstrap.java:200)
    at io.netty.bootstrap.Bootstrap.access$000(Bootstrap.java:46)
    at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:180)
    at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:166)
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577)
    at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:551)
    at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:490)
    at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:615)
    at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:604)
    at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
    at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.safeSetSuccess(AbstractChannel.java:984)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:504)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:417)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:474)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.lang.Thread.run(Unknown Source)
18:36:23.881 [ForkJoinPool.commonPool-worker-1] ERROR o.e.m.e.client.ClientExampleRunner - Error running example: java.net.UnknownHostException: br-automation
java.util.concurrent.ExecutionException: java.net.UnknownHostException: br-automation
    at java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
    at java.util.concurrent.CompletableFuture.get(Unknown Source)
    at org.eclipse.milo.examples.client.SubscriptionExample.run(SubscriptionExample.java:50)
    at org.eclipse.milo.examples.client.ClientExampleRunner.run(ClientExampleRunner.java:120)
    at org.eclipse.milo.examples.client.SubscriptionExample.main(SubscriptionExample.java:42)
Caused by: java.net.UnknownHostException: br-automation
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)
    at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
    at java.net.InetAddress.getAllByName0(Unknown Source)
    at java.net.InetAddress.getAllByName(Unknown Source)
    at java.net.InetAddress.getAllByName(Unknown Source)
    at java.net.InetAddress.getByName(Unknown Source)
    at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:148)
    at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:145)
    at java.security.AccessController.doPrivileged(Native Method)
    at io.netty.util.internal.SocketUtils.addressByName(SocketUtils.java:145)
    at io.netty.resolver.DefaultNameResolver.doResolve(DefaultNameResolver.java:43)
    at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:63)
    at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:55)
    at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:57)
    at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:32)
    at io.netty.resolver.AbstractAddressResolver.resolve(AbstractAddressResolver.java:108)
    at io.netty.bootstrap.Bootstrap.doResolveAndConnect0(Bootstrap.java:200)
    at io.netty.bootstrap.Bootstrap.access$000(Bootstrap.java:46)
    at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:180)
    at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:166)
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577)
    at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:551)
    at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:490)
    at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:615)
    at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:604)
    at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
    at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.safeSetSuccess(AbstractChannel.java:984)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:504)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:417)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:474)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.lang.Thread.run(Unknown Source)

当使用UaExpert时,“opc”。tcp://11.23.1.1:4840“是我在使用自定义发现时添加新服务器时输入的服务器地址。当我输入此地址时,一个名为B的设备显示为该服务器的下拉列表。”

用于调用GetEndpoints(br automation)的发现URL的主机名已替换为用于调用FindServer(11.23.1.1)的主机名。是否还要用此主机名替换EndpointURLs的主机名?

我必须接受这条消息才能找到服务器,但我很困惑到底发生了什么。我假设用于查找服务器的endpoint和用于其他东西的endpoint有区别?我发现在线资源很难理解。在UaProfessional日志中有一行三行日志报告“Adding Url:ocp.tcp://br-自动化: 4840”。然后它还报告endpoint:“ocp.tcp://br-自动化: 4840”、应用程序Uri和安全策略(无)。如果我尝试将客户端getEndpoint Url方法中的地址更改为ocp.tcp://br-自动化: 4840,则会出现以下错误:

[main] INFO  o.e.m.opcua.sdk.client.OpcUaClient - Eclipse Milo OPC UA Client SDK version: 0.4.3-SNAPSHOT
18:37:46.035 [main] ERROR o.e.m.e.client.ClientExampleRunner - Error getting client: java.util.concurrent.ExecutionException: java.net.UnknownHostException: br-automation
org.eclipse.milo.opcua.stack.core.UaException: java.util.concurrent.ExecutionException: java.net.UnknownHostException: br-automation
    at org.eclipse.milo.opcua.sdk.client.OpcUaClient.lambda$create$1(OpcUaClient.java:204)
    at java.util.Optional.orElseGet(Unknown Source)
    at org.eclipse.milo.opcua.sdk.client.OpcUaClient.create(OpcUaClient.java:204)
    at org.eclipse.milo.opcua.sdk.client.OpcUaClient.create(OpcUaClient.java:201)
    at org.eclipse.milo.examples.client.ClientExampleRunner.createClient(ClientExampleRunner.java:73)
    at org.eclipse.milo.examples.client.ClientExampleRunner.run(ClientExampleRunner.java:94)
    at org.eclipse.milo.examples.client.SubscriptionExample.main(SubscriptionExample.java:42)
Caused by: java.util.concurrent.ExecutionException: java.net.UnknownHostException: br-automation
    at java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
    at java.util.concurrent.CompletableFuture.get(Unknown Source)
    at org.eclipse.milo.opcua.sdk.client.OpcUaClient.create(OpcUaClient.java:180)
    ... 4 common frames omitted
Caused by: java.net.UnknownHostException: br-automation
    at java.net.InetAddress.getAllByName0(Unknown Source)
    at java.net.InetAddress.getAllByName(Unknown Source)
    at java.net.InetAddress.getAllByName(Unknown Source)
    at java.net.InetAddress.getByName(Unknown Source)
    at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:148)
    at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:145)
    at java.security.AccessController.doPrivileged(Native Method)
    at io.netty.util.internal.SocketUtils.addressByName(SocketUtils.java:145)
    at io.netty.resolver.DefaultNameResolver.doResolve(DefaultNameResolver.java:43)
    at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:63)
    at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:55)
    at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:57)
    at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:32)
    at io.netty.resolver.AbstractAddressResolver.resolve(AbstractAddressResolver.java:108)
    at io.netty.bootstrap.Bootstrap.doResolveAndConnect0(Bootstrap.java:200)
    at io.netty.bootstrap.Bootstrap.access$000(Bootstrap.java:46)
    at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:180)
    at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:166)
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:577)
    at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:551)
    at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:490)
    at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:615)
    at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:604)
    at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:104)
    at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.safeSetSuccess(AbstractChannel.java:984)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:504)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:417)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:474)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.lang.Thread.run(Unknown Source)

我不知道这是否足以诊断问题,但我希望您能帮助我如何让Eclipse Milo服务器执行相同的进程并连接到机器的服务器。

共有3个答案

萧浩漫
2023-03-14

我们能够解决我们的问题,通过手动用主机IP和端口覆盖从OPC UA服务器返回的主机名。(参见try语句的第二行)

public class OpcUaConnection {
    OpcUaClient client;
    final int NAMESPACEINDEX = 6;

    private static final AtomicLong clientHandles = new AtomicLong(1L);

    public OpcUaConnection() {
        try {
            List<EndpointDescription> endpoints = DiscoveryClient.getEndpoints("opc.tcp://192.168.0.122:4840").get();
            EndpointDescription configPoint = EndpointUtil.updateUrl(endpoints.get(0), "192.168.0.122", 4840);

            OpcUaClientConfigBuilder cfg = new OpcUaClientConfigBuilder();
            cfg.setEndpoint(configPoint);

            this.client = OpcUaClient.create(cfg.build());
            client.connect().get();

        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }

希望这能帮助其他人!

吕森
2023-03-14

您可以使用服务器日志找到连接服务器的正确主机名/URL。服务器日志启动后,打印所有有效的UR

夏谦
2023-03-14

问题是,运行客户端的计算机无法将主机名“br automation”解析为IP地址。

如果无法将服务器配置为返回IP地址,则解决方案是手动重新生成从GetEndpoints服务调用获得的EndpointDescriptions,以便它们具有包含IP地址而不是主机名的endpointURL。这就是UaExpert在幕后警告您更换主机名时所做的。

您可以使用EndpointUtil#updateUrl在传递到OpcUaClientConfig之前构建一个新的EndpointDescription

 类似资料:
  • 首先:我是OPCUA的新手。:) 我正在尝试将Milo客户端连接到我们的服务器,但不真正了解出了什么问题。示例客户端和服务器一起工作很好,但当我尝试将客户端示例与公共OPC-UA-Test-Servers之一连接时,我得到了这些例外: 15:48:34.729[ua-netty-event-lop-0]DEBUGorg.eclipse.milo.opcua.stack.client.handler

  • 我有milo opcua服务器与启用并使用设置用户名和密码。 从milo客户端,我使用设置。 当我运行此设置时,一切正常。 但当我重新启动opcua服务器时,milo客户端将无法重新连接。我得到以下例外: [milo-shared-thread-pool-2]跳过证书的验证:C=DE,ST=“”,L=Locality,OU=OrganizationUnit,O=Organization,CN=Ag

  • 我是OPC UA的新手,我正在使用milo OPC订阅者客户端连接到本地发现服务。我有Prosys模拟服务器,它连接到我的本地发现服务。 注意:如果我直接连接到prosysendpoint,它可以正常工作。它仅通过发现服务失败。 运行代码时会出现以下异常 在ClientRunner中创建客户端的代码。 客户端接口类 订阅服务器运行实现

  • 我创建了spring项目来对postgres数据库服务器进行CRUD,但出现了一些错误。 无法获得查询元数据的连接 组织。postgresql。util。PSQLException:连接尝试失败。在org。postgresql。果心v3。连接工厂impl。openConnectionImpl(ConnectionFactoryImpl.java:313)~[postgresql-42.3.1.ja

  • 问题内容: 我试图绕过 ObjectInputStream / ObjectOutputStream ,所以我创建了一个非常简单的服务器- 客户端应用程序,其中客户端通过创建的流发送HashMap对象,服务器接收并打印该对象。 这是我的服务器代码: 这是我的客户代码: 我运行服务器文件,它运行正常。 然后运行客户端文件,并在服务器上收到以下错误: PS我不知道我是否需要做一些事情来序列化HashM

  • 关于上面的问题,我想请您帮忙。现在我正在尝试将应用程序(SpringCloudConfigServer)与另一个应用程序(limit-service)连接,limit-service应用程序必须选择SpringCloudConfigServer属性文件。当我点击http://localhost:8080/limits时,我需要像{“maximum”:888,“minimum”:8}一样获得oupp