Created
October 27, 2016 16:23
-
-
Save erossignon/b188a0f84254034e6c92df0e82d1a8ac to your computer and use it in GitHub Desktop.
2 servers in the same process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var opcua = require("node-opcua"); | |
var path = require("path"); | |
var port1 = 25000 | |
var port2 = 25001 | |
var standard_nodeset_file = opcua.standard_nodeset_file; | |
var rootFolder = path.join(__dirname,"./"); | |
var server_certificate_file = path.join(rootFolder, "certificates/server_cert_1024.pem"); | |
var server_certificate_privatekey_file = path.join(rootFolder, "certificates/server_key_1024.pem"); | |
var server_options1 = { | |
certificateFile: server_certificate_file, | |
privateKeyFile: server_certificate_privatekey_file, | |
port: port1, | |
nodeset_filename: [ | |
standard_nodeset_file | |
] | |
}; | |
var server_options2 = { | |
certificateFile: server_certificate_file, | |
privateKeyFile: server_certificate_privatekey_file, | |
port: port2, | |
nodeset_filename: [ | |
standard_nodeset_file | |
] | |
}; | |
process.title = "Node OPCUA Server on port : " + server_options1.port; | |
var server1 = new opcua.OPCUAServer(server_options1); | |
server1.on("post_initialize", function () { | |
var addressSpace = server1.engine.addressSpace; | |
var rootFolder = addressSpace.findNode("RootFolder"); | |
var node1 = addressSpace.addObject({ | |
browseName:"MySpecialObjectOnlyVisibleInServer1", | |
organizedBy: rootFolder.objects | |
}); | |
}); | |
server1.start(function (err) { | |
if (err) { | |
console.log(" Server failed to start ... exiting"); | |
process.exit(-3); | |
} | |
console.log(" server on port :".yellow, server1.endpoints[0].port.toString().cyan); | |
}); | |
var server2 = new opcua.OPCUAServer(server_options2); | |
server2.on("post_initialize", function () { | |
var addressSpace = server2.engine.addressSpace; | |
var rootFolder = addressSpace.findNode("RootFolder"); | |
var node1 = addressSpace.addObject({ | |
browseName:"MySpecialObjectOnlyVisibleInServer2", | |
organizedBy: rootFolder.objects | |
}); | |
}); | |
server2.start(function (err) { | |
if (err) { | |
console.log(" Server failed to start ... exiting"); | |
process.exit(-3); | |
} | |
console.log(" server on port :".yellow, server2.endpoints[0].port.toString().cyan); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment