node-opcua-samples 2.97.0 → 2.98.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/get_endpoints.d.ts +2 -2
- package/dist/get_endpoints.js +141 -141
- package/dist/mini_server.d.ts +1 -1
- package/dist/mini_server.js +88 -88
- package/dist/server_with_changing_password.d.ts +1 -1
- package/dist/server_with_changing_password.js +100 -100
- package/dist/server_with_push_certificate.d.ts +2 -2
- package/dist/server_with_push_certificate.js +111 -111
- package/dist/simple_client_ts.d.ts +2 -2
- package/dist/simple_client_ts.js +661 -661
- package/dist/simple_findservers.d.ts +2 -2
- package/dist/simple_findservers.js +48 -48
- package/dist/simple_secure_server.d.ts +2 -2
- package/dist/simple_secure_server.js +125 -125
- package/dist/simple_server_with_custom_extension_objects.d.ts +2 -2
- package/dist/simple_server_with_custom_extension_objects.js +81 -81
- package/dist/stressing_client.d.ts +1 -1
- package/dist/stressing_client.js +36 -36
- package/dist/tiny_client.d.ts +1 -1
- package/dist/tiny_client.js +32 -32
- package/package.json +15 -12
- package/bin/createOPCUACertificate.cmd +0 -6
- package/bin/create_certificates.js +0 -2
- package/bin/crypto_create_CA.js +0 -2
- package/bin/demo_server_with_alarm.js +0 -51
- package/bin/findServersOnNetwork.js +0 -32
- package/bin/get_endpoints.ts +0 -166
- package/bin/machineryServer.js +0 -83
- package/bin/mini_server.ts +0 -106
- package/bin/more.js +0 -40
- package/bin/node-opcua.js +0 -2
- package/bin/opcua_interceptor.js +0 -122
- package/bin/server_with_changing_password.ts +0 -97
- package/bin/server_with_push_certificate.ts +0 -122
- package/bin/simple_client.js +0 -830
- package/bin/simple_client_ts.ts +0 -847
- package/bin/simple_findservers.ts +0 -45
- package/bin/simple_secure_server.ts +0 -152
- package/bin/simple_server_with_custom_extension_objects.ts +0 -89
- package/bin/stressing_client.ts +0 -28
- package/bin/tiny_client.ts +0 -24
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
// tslint:disable:no-console
|
|
3
|
-
// this script queries the discovery server and display the discovery urls
|
|
4
|
-
import * as chalk from "chalk";
|
|
5
|
-
import { MessageSecurityMode, ApplicationType, findServers } from "node-opcua";
|
|
6
|
-
|
|
7
|
-
async function main() {
|
|
8
|
-
const discovery_server_endpointUrl = "opc.tcp://localhost:4840/UADiscovery";
|
|
9
|
-
|
|
10
|
-
console.log("Interrogating ", discovery_server_endpointUrl);
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
const { servers, endpoints } = await findServers(discovery_server_endpointUrl);
|
|
14
|
-
for (const server of servers) {
|
|
15
|
-
console.log(" applicationUri:", chalk.cyan.bold(server.applicationUri!));
|
|
16
|
-
console.log(" productUri:", chalk.cyan.bold(server.productUri!));
|
|
17
|
-
console.log(" applicationName:", chalk.cyan.bold(server.applicationName!.text!));
|
|
18
|
-
console.log(" type:", chalk.cyan.bold(ApplicationType[server.applicationType]));
|
|
19
|
-
console.log(" gatewayServerUri:", server.gatewayServerUri ? chalk.cyan.bold(server.gatewayServerUri) : "");
|
|
20
|
-
console.log("discoveryProfileUri:", server.discoveryProfileUri ? chalk.cyan.bold(server.discoveryProfileUri) : "");
|
|
21
|
-
console.log(" discoveryUrls:");
|
|
22
|
-
|
|
23
|
-
for (const discoveryUrl of server.discoveryUrls!) {
|
|
24
|
-
console.log(" " + chalk.cyan.bold(discoveryUrl!));
|
|
25
|
-
}
|
|
26
|
-
console.log("-------------");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
for (const endpoint of endpoints) {
|
|
30
|
-
console.log(
|
|
31
|
-
endpoint.endpointUrl!.toString(),
|
|
32
|
-
endpoint.securityLevel,
|
|
33
|
-
endpoint.securityPolicyUri,
|
|
34
|
-
MessageSecurityMode[endpoint.securityMode]
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
} catch (err) {
|
|
38
|
-
if (err instanceof Error) {
|
|
39
|
-
console.log("err ", err.message);
|
|
40
|
-
}
|
|
41
|
-
process.exit(-2);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
main();
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
/* eslint no-process-exit: 0 */
|
|
3
|
-
// tslint:disable:no-console
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import * as os from "os";
|
|
6
|
-
|
|
7
|
-
import * as chalk from "chalk";
|
|
8
|
-
import * as yargs from "yargs";
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
makeApplicationUrn,
|
|
12
|
-
MessageSecurityMode,
|
|
13
|
-
nodesets,
|
|
14
|
-
OPCUAServer,
|
|
15
|
-
OPCUAServerOptions,
|
|
16
|
-
SecurityPolicy,
|
|
17
|
-
ServerSession
|
|
18
|
-
} from "node-opcua";
|
|
19
|
-
|
|
20
|
-
Error.stackTraceLimit = Infinity;
|
|
21
|
-
|
|
22
|
-
function constructFilename(filename: string): string {
|
|
23
|
-
return path.join(__dirname, "../", filename);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const userManager = {
|
|
27
|
-
isValidUser: (userName: string, password: string) => {
|
|
28
|
-
if (userName === "user1" && password === "password1") {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
if (userName === "user2" && password === "password2") {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
async function main() {
|
|
39
|
-
const argv = await yargs(process.argv)
|
|
40
|
-
.wrap(132)
|
|
41
|
-
|
|
42
|
-
.option("alternateHostname", {
|
|
43
|
-
alias: "a",
|
|
44
|
-
describe: "alternateHostname"
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
.option("port", {
|
|
48
|
-
alias: "p",
|
|
49
|
-
default: 26543
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
.option("silent", {
|
|
53
|
-
alias: "s",
|
|
54
|
-
default: false,
|
|
55
|
-
describe: "silent - no trace"
|
|
56
|
-
})
|
|
57
|
-
.option("maxSessions", {
|
|
58
|
-
alias: "m",
|
|
59
|
-
default: 10
|
|
60
|
-
})
|
|
61
|
-
.help(true).argv;
|
|
62
|
-
|
|
63
|
-
const port = argv.port || 26543;
|
|
64
|
-
// server_options.alternateHostname = argv.alternateHostname;
|
|
65
|
-
|
|
66
|
-
const server_options: OPCUAServerOptions = {
|
|
67
|
-
securityPolicies: [SecurityPolicy.Basic128Rsa15, SecurityPolicy.Basic256],
|
|
68
|
-
|
|
69
|
-
securityModes: [MessageSecurityMode.Sign, MessageSecurityMode.SignAndEncrypt],
|
|
70
|
-
|
|
71
|
-
port,
|
|
72
|
-
|
|
73
|
-
nodeset_filename: [nodesets.standard, nodesets.di],
|
|
74
|
-
|
|
75
|
-
serverInfo: {
|
|
76
|
-
applicationName: { text: "NodeOPCUA", locale: "en" },
|
|
77
|
-
applicationUri: makeApplicationUrn(os.hostname(), "NodeOPCUA-SecureServer"),
|
|
78
|
-
productUri: "NodeOPCUA-SecureServer",
|
|
79
|
-
|
|
80
|
-
discoveryProfileUri: null,
|
|
81
|
-
discoveryUrls: [],
|
|
82
|
-
gatewayServerUri: null
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
buildInfo: {
|
|
86
|
-
buildDate: new Date(),
|
|
87
|
-
buildNumber: "1234"
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
serverCapabilities: {
|
|
91
|
-
maxSessions: argv.maxSessions
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
maxConnectionsPerEndpoint: argv.maxSessions,
|
|
95
|
-
|
|
96
|
-
userManager,
|
|
97
|
-
|
|
98
|
-
isAuditing: false
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
process.title = "Node OPCUA Server on port : " + server_options.port;
|
|
102
|
-
|
|
103
|
-
const server = new OPCUAServer(server_options);
|
|
104
|
-
|
|
105
|
-
server.on("post_initialize", () => {
|
|
106
|
-
/* empty */
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
console.log(chalk.yellow(" server PID :"), process.pid);
|
|
110
|
-
console.log(chalk.yellow(" silent :"), argv.silent);
|
|
111
|
-
|
|
112
|
-
await server.start();
|
|
113
|
-
|
|
114
|
-
const endpointUrl = server.getEndpointUrl()!;
|
|
115
|
-
console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
|
|
116
|
-
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
|
|
117
|
-
|
|
118
|
-
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
|
|
119
|
-
|
|
120
|
-
if (argv.silent) {
|
|
121
|
-
console.log("silent");
|
|
122
|
-
console.log = (...args: [any?, ...any[]]) => {
|
|
123
|
-
/* silent */
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
server.on("create_session", (session: ServerSession) => {
|
|
128
|
-
console.log(" SESSION CREATED");
|
|
129
|
-
console.log(chalk.cyan(" client application URI: "), session.clientDescription!.applicationUri);
|
|
130
|
-
console.log(chalk.cyan(" client product URI: "), session.clientDescription!.productUri);
|
|
131
|
-
console.log(chalk.cyan(" client application name: "), session.clientDescription!.applicationName.toString());
|
|
132
|
-
console.log(chalk.cyan(" client application type: "), session.clientDescription!.applicationType.toString());
|
|
133
|
-
console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
|
|
134
|
-
console.log(chalk.cyan(" session timeout: "), session.sessionTimeout);
|
|
135
|
-
console.log(chalk.cyan(" session id: "), session.nodeId);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
server.on("session_closed", (session: ServerSession, reason: string) => {
|
|
139
|
-
console.log(" SESSION CLOSED :", reason);
|
|
140
|
-
console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
process.on("SIGINT", async () => {
|
|
144
|
-
// only work on linux apparently
|
|
145
|
-
console.error(chalk.red.bold(" Received server interruption from user "));
|
|
146
|
-
console.error(chalk.red.bold(" shutting down ..."));
|
|
147
|
-
await server.shutdown(1000);
|
|
148
|
-
console.error(chalk.red.bold(" shot down ..."));
|
|
149
|
-
process.exit(1);
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
main();
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ts-node
|
|
2
|
-
/* eslint no-process-exit: 0 */
|
|
3
|
-
// tslint:disable:no-console
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import * as chalk from "chalk";
|
|
6
|
-
import { nodesets, OPCUAServer } from "node-opcua";
|
|
7
|
-
import * as yargs from "yargs";
|
|
8
|
-
import { Argv } from "yargs";
|
|
9
|
-
|
|
10
|
-
Error.stackTraceLimit = Infinity;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function constructFilename(filename: string): string {
|
|
14
|
-
return path.join(__dirname, "../", filename);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const rootFolder = path.join(__dirname, "../../..");
|
|
18
|
-
|
|
19
|
-
async function main() {
|
|
20
|
-
|
|
21
|
-
const argv = await yargs.wrap(132).option("port", {
|
|
22
|
-
alias: "p",
|
|
23
|
-
default: "26543",
|
|
24
|
-
describe: "port to listen"
|
|
25
|
-
}).argv;
|
|
26
|
-
const port = parseInt(argv.port, 10) || 26555;
|
|
27
|
-
const server_certificate_file = constructFilename("certificates/server_cert_2048.pem");
|
|
28
|
-
const server_certificate_privatekey_file = constructFilename("certificates/server_key_2048.pem");
|
|
29
|
-
|
|
30
|
-
const server_options = {
|
|
31
|
-
certificateFile: server_certificate_file,
|
|
32
|
-
privateKeyFile: server_certificate_privatekey_file,
|
|
33
|
-
|
|
34
|
-
port,
|
|
35
|
-
|
|
36
|
-
nodeset_filename: [nodesets.standard, path.join(rootFolder, "modeling/my_data_type.xml")]
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
process.title = "Node OPCUA Server on port : " + server_options.port;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const server = new OPCUAServer(server_options);
|
|
43
|
-
|
|
44
|
-
console.log(chalk.yellow(" server PID :"), process.pid);
|
|
45
|
-
|
|
46
|
-
server.on("post_initialize", () => {
|
|
47
|
-
const addressSpace = server.engine.addressSpace!;
|
|
48
|
-
|
|
49
|
-
// to do: expose new nodeid here
|
|
50
|
-
const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
|
|
51
|
-
const myStructureType = addressSpace.findVariableType("MyStructureType", ns);
|
|
52
|
-
if (!myStructureType) {
|
|
53
|
-
console.log(" ns = ", ns, "cannot find MyStructureDataType ");
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const namespace = addressSpace.getOwnNamespace();
|
|
58
|
-
const someObject = namespace.addObject({
|
|
59
|
-
browseName: "SomeObject",
|
|
60
|
-
organizedBy: addressSpace.rootFolder.objects
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
myStructureType.instantiate({
|
|
64
|
-
browseName: "MyVar",
|
|
65
|
-
componentOf: someObject
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
await server.start();
|
|
71
|
-
} catch (err) {
|
|
72
|
-
console.log(" Server failed to start ... exiting");
|
|
73
|
-
process.exit(-3);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const endpointUrl = server.getEndpointUrl()!;
|
|
77
|
-
|
|
78
|
-
console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
|
|
79
|
-
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
|
|
80
|
-
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
|
|
81
|
-
|
|
82
|
-
process.on("SIGINT", async () => {
|
|
83
|
-
// only work on linux apparently
|
|
84
|
-
await server.shutdown(1000);
|
|
85
|
-
console.log(chalk.red.bold(" shutting down completed "));
|
|
86
|
-
process.exit(-1);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
main();
|
package/bin/stressing_client.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import { OPCUAClient } from "node-opcua";
|
|
3
|
-
|
|
4
|
-
const endpointUrl = "opc.tcp://localhost:26543";
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
let counter = 1;
|
|
8
|
-
|
|
9
|
-
while (true) {
|
|
10
|
-
const client = OPCUAClient.create({ endpointMustExist: false });
|
|
11
|
-
client.on("backoff", (retryCount: number, delay: number) => console.log(" backoff", retryCount, delay));
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
await client.connect(endpointUrl);
|
|
15
|
-
const session = await client.createSession();
|
|
16
|
-
await session.close();
|
|
17
|
-
await client.disconnect();
|
|
18
|
-
} catch (err) {
|
|
19
|
-
if (err instanceof Error) {
|
|
20
|
-
console.log("err", err.message);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
console.log(" Connected = ", counter++);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
main();
|
package/bin/tiny_client.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
process.env.NODEOPCUADEBUG = "CLIENT{TRACE};TRANSPORT{CHUNK-HELACK}";
|
|
2
|
-
import { OPCUAClient } from "node-opcua";
|
|
3
|
-
|
|
4
|
-
(async () => {
|
|
5
|
-
const client = OPCUAClient.create({
|
|
6
|
-
requestedSessionTimeout: 1000,
|
|
7
|
-
transportSettings: {
|
|
8
|
-
maxChunkCount: 1,
|
|
9
|
-
maxMessageSize: 1 * 8192, // should be at least 8192
|
|
10
|
-
receiveBufferSize: 8 * 1024,
|
|
11
|
-
sendBufferSize: 8 * 1024
|
|
12
|
-
},
|
|
13
|
-
connectionStrategy: {
|
|
14
|
-
initialDelay: 10,
|
|
15
|
-
maxDelay: 100,
|
|
16
|
-
maxRetry: 2
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
await client.connect("opc.tcp://localhost:48010");
|
|
21
|
-
// await client.connect("opc.tcp://localhost:53530");
|
|
22
|
-
|
|
23
|
-
await client.disconnect();
|
|
24
|
-
})();
|