node-opcua
node-opcua copied to clipboard
Discovering OPCUA Servers running on the same network using mDNS [QUESTION]
Hi there,
I'm trying to get MDNS server registry working, but I'm not seeing the behavior that I expected. Basically, I'm looking for a way to spawn an OPCUAServer instance which is discoverable by clients on the same local network without any additional configuration (i.e. without explicitly spinning up a separate local discovery server running on a different machine, whose URI would need to be known a priori by clients).
In my server application, I'm creating an OPCUAServer class like so:
const server = new OPCUAServer({
port: config.serverApiPort, // the port of the listening socket of the server
allowAnonymous: false,
registerServerMethod: RegisterServerMethod.MDNS,
securityModes: [MessageSecurityMode.SignAndEncrypt],
securityPolicies: [SecurityPolicy.Basic256Sha256],
});
Then in my client application, I'm attempting to extract a url to pass to findServersOnNetwork()
by creating a discovery server (it feels like I'm doing something incorrectly here):
const lds = new OPCUADiscoveryServer({
serverInfo: {}
})
await lds.start();
const url= lds._get_endpoints()[0].endpointUrl;
const servers = await findServersOnNetwork(url);
await lds.shutdown();
return servers
.filter((server) => {
const { serverCapabilities } = server;
return !serverCapabilities.includes("LDS"); // Ignore other discovery servers
When I run both the client and the server on the same machine, the client is able to discover and connect to the server. However, when I run them on separate machines (but on the same local network), the client does not detect the server. I'm relatively new to OPCUA stuff, so apologies if this question is framed poorly, but any and all help would be much appreciated -- thanks a bunch!
You'll need a standard discovery server on each physical machine( they both use the well know endpoint URL for local discovery server opc.tcp://localhost:4841) The two local discovery servers will be syncing one an other using the mDNS mechanism, each local discovery server will be able to display the connected servers available on the other physical servers along side with its own connected local servers.