node-opcua-samples 2.175.6 → 2.176.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/reverse_connect_client.d.ts +1 -0
- package/dist/reverse_connect_client.js +57 -0
- package/dist/reverse_connect_client.js.map +1 -0
- package/dist/reverse_connect_server.d.ts +1 -0
- package/dist/reverse_connect_server.js +66 -0
- package/dist/reverse_connect_server.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// Reverse Connect CLIENT example (OPC UA Part 6 §7.1.3)
|
|
7
|
+
//
|
|
8
|
+
// In a reverse connection the SERVER dials the socket. This client therefore opens a TCP listener
|
|
9
|
+
// and WAITS for the server to connect and send a ReverseHello, then establishes the session as usual.
|
|
10
|
+
//
|
|
11
|
+
// Run this client first (it opens the listener), then the server:
|
|
12
|
+
//
|
|
13
|
+
// npx tsx bin/reverse_connect_client.ts # terminal 1 - listens on 127.0.0.1:6666
|
|
14
|
+
// npx tsx bin/reverse_connect_server.ts # terminal 2 - dials into it
|
|
15
|
+
//
|
|
16
|
+
// Everything runs on 127.0.0.1 so it works on a single machine.
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const node_opcua_1 = require("node-opcua");
|
|
19
|
+
// the address this client listens on for incoming (server-initiated) connections
|
|
20
|
+
const reverseListenUrl = "opc.tcp://127.0.0.1:6666";
|
|
21
|
+
async function main() {
|
|
22
|
+
// 1) open the reverse-connect listener; multiple clients can share one listener.
|
|
23
|
+
const reverseConnect = new node_opcua_1.ClientReverseConnect(reverseListenUrl);
|
|
24
|
+
await reverseConnect.start();
|
|
25
|
+
console.log(chalk_1.default.yellow(" waiting for a server to dial in on :"), chalk_1.default.cyan(reverseListenUrl));
|
|
26
|
+
// 2) create a client and wait for the server to connect.
|
|
27
|
+
// Passing an `expectation` (e.g. { serverUri }) restricts which server may connect;
|
|
28
|
+
// here we accept any server for simplicity. For SECURED connections you must also
|
|
29
|
+
// provide the server certificate up front (securityMode/securityPolicy + serverCertificate),
|
|
30
|
+
// because the client cannot dial the server to fetch it.
|
|
31
|
+
const client = node_opcua_1.OPCUAClient.create({
|
|
32
|
+
clientName: "ReverseConnect-Client",
|
|
33
|
+
endpointMustExist: false
|
|
34
|
+
});
|
|
35
|
+
client.on("connection_reestablished", () => console.log(chalk_1.default.green(" reverse connection re-established")));
|
|
36
|
+
client.on("connection_lost", () => console.log(chalk_1.default.red(" connection lost - waiting for the server to re-dial ...")));
|
|
37
|
+
console.log(chalk_1.default.green(" connectReverse(): blocking until the server dials in ..."));
|
|
38
|
+
await client.connectReverse(reverseConnect /*, { serverUri: "urn:...:ReverseConnect-Server" } */);
|
|
39
|
+
console.log(chalk_1.default.green(" connected! creating a session ..."));
|
|
40
|
+
const session = await client.createSession();
|
|
41
|
+
// read the server's current time (i=2258) as a smoke test
|
|
42
|
+
const dataValue = await session.read({ nodeId: "i=2258", attributeId: node_opcua_1.AttributeIds.Value });
|
|
43
|
+
console.log(chalk_1.default.yellow(" server current time :"), chalk_1.default.cyan(String(dataValue.value.value)));
|
|
44
|
+
console.log(chalk_1.default.green(" reverse connection is up. Press CTRL+C to stop."));
|
|
45
|
+
process.on("SIGINT", async () => {
|
|
46
|
+
console.log(" shutting down ...");
|
|
47
|
+
await session.close();
|
|
48
|
+
await client.disconnect();
|
|
49
|
+
await reverseConnect.stop();
|
|
50
|
+
process.exit(0);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
main().catch((err) => {
|
|
54
|
+
console.log(chalk_1.default.red(" client failed: "), err.message);
|
|
55
|
+
process.exit(-1);
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=reverse_connect_client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reverse_connect_client.js","sourceRoot":"","sources":["../bin/reverse_connect_client.ts"],"names":[],"mappings":";;;;;AAAA,wDAAwD;AACxD,EAAE;AACF,kGAAkG;AAClG,sGAAsG;AACtG,EAAE;AACF,kEAAkE;AAClE,EAAE;AACF,4FAA4F;AAC5F,gFAAgF;AAChF,EAAE;AACF,gEAAgE;AAChE,kDAA0B;AAC1B,2CAA6E;AAE7E,iFAAiF;AACjF,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAEpD,KAAK,UAAU,IAAI;IACf,iFAAiF;IACjF,MAAM,cAAc,GAAG,IAAI,iCAAoB,CAAC,gBAAgB,CAAC,CAAC;IAClE,MAAM,cAAc,CAAC,KAAK,EAAE,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,wCAAwC,CAAC,EAAE,eAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAElG,yDAAyD;IACzD,uFAAuF;IACvF,qFAAqF;IACrF,gGAAgG;IAChG,4DAA4D;IAC5D,MAAM,MAAM,GAAG,wBAAW,CAAC,MAAM,CAAC;QAC9B,UAAU,EAAE,uBAAuB;QACnC,iBAAiB,EAAE,KAAK;KAC3B,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC,CAAC,CAAC;IAC5G,MAAM,CAAC,EAAE,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC,CAAC,CAAC;IAEvH,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,4DAA4D,CAAC,CAAC,CAAC;IACvF,MA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 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// Reverse Connect SERVER example (OPC UA Part 6 §7.1.3)
|
|
7
|
+
//
|
|
8
|
+
// Instead of waiting for clients to dial in, this server DIALS OUT to a client's reverse-connect
|
|
9
|
+
// listener and sends a ReverseHello. This is useful when the server sits behind a firewall / NAT
|
|
10
|
+
// with no inbound ports open.
|
|
11
|
+
//
|
|
12
|
+
// Run the client first (it opens the listener), then this server:
|
|
13
|
+
//
|
|
14
|
+
// npx tsx bin/reverse_connect_client.ts # terminal 1 - listens on 127.0.0.1:6666
|
|
15
|
+
// npx tsx bin/reverse_connect_server.ts # terminal 2 - dials into it
|
|
16
|
+
//
|
|
17
|
+
// Everything runs on 127.0.0.1 so it works on a single machine.
|
|
18
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
19
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
20
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
21
|
+
const env_paths_1 = __importDefault(require("env-paths"));
|
|
22
|
+
const node_opcua_1 = require("node-opcua");
|
|
23
|
+
// the client's reverse-connect listener that this server will dial into
|
|
24
|
+
const clientReverseUrl = "opc.tcp://127.0.0.1:6666";
|
|
25
|
+
const pkiFolder = node_path_1.default.join((0, env_paths_1.default)("ReverseConnect-Server").config, "PKI");
|
|
26
|
+
const serverOptions = {
|
|
27
|
+
serverCertificateManager: new node_opcua_1.OPCUACertificateManager({ rootFolder: pkiFolder }),
|
|
28
|
+
port: 26544,
|
|
29
|
+
nodeset_filename: [(0, node_opcua_1.get_mini_nodeset_filename)()],
|
|
30
|
+
serverInfo: {
|
|
31
|
+
applicationUri: (0, node_opcua_1.makeApplicationUrn)(node_os_1.default.hostname(), "ReverseConnect-Server")
|
|
32
|
+
},
|
|
33
|
+
// ← the reverse-connect configuration: all fields but `connections` are optional
|
|
34
|
+
reverseConnect: {
|
|
35
|
+
connections: [{ endpointUrl: clientReverseUrl }],
|
|
36
|
+
reconnectDelay: 2000
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
async function main() {
|
|
40
|
+
const server = new node_opcua_1.OPCUAServer(serverOptions);
|
|
41
|
+
console.log(chalk_1.default.yellow(" server PID :"), process.pid);
|
|
42
|
+
try {
|
|
43
|
+
await server.start();
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.log(" Server failed to start ... exiting");
|
|
47
|
+
process.exit(-3);
|
|
48
|
+
}
|
|
49
|
+
console.log(chalk_1.default.yellow(" applicationUri :"), chalk_1.default.cyan(server.serverInfo.applicationUri));
|
|
50
|
+
console.log(chalk_1.default.yellow(" local endpointUrl :"), chalk_1.default.cyan(server.getEndpointUrl()));
|
|
51
|
+
console.log(chalk_1.default.yellow(" reverse-connecting to:"), chalk_1.default.cyan(clientReverseUrl));
|
|
52
|
+
console.log(chalk_1.default.green(" the server is now dialing the reverse-connect client and (re)sending ReverseHello..."));
|
|
53
|
+
server.on("create_session", (session) => {
|
|
54
|
+
console.log(chalk_1.default.green(" SESSION CREATED (via reverse connection) :"), session.sessionName);
|
|
55
|
+
});
|
|
56
|
+
server.on("session_closed", (session) => {
|
|
57
|
+
console.log(chalk_1.default.red(" SESSION CLOSED :"), session.sessionName);
|
|
58
|
+
});
|
|
59
|
+
process.on("SIGINT", async () => {
|
|
60
|
+
console.log(" shutting down ...");
|
|
61
|
+
await server.shutdown();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
main();
|
|
66
|
+
//# sourceMappingURL=reverse_connect_server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reverse_connect_server.js","sourceRoot":"","sources":["../bin/reverse_connect_server.ts"],"names":[],"mappings":";;;;;AAAA,wDAAwD;AACxD,EAAE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
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.176.1",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module samples",
|
|
5
5
|
"bin": {
|
|
6
6
|
"simple_client": "./dist/simple_client_ts.js",
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
"chalk": "4.1.2",
|
|
23
23
|
"easy-table": "^1.2.0",
|
|
24
24
|
"env-paths": "2.2.1",
|
|
25
|
-
"node-opcua": "2.
|
|
26
|
-
"node-opcua-address-space": "2.
|
|
27
|
-
"node-opcua-address-space-for-conformance-testing": "2.
|
|
25
|
+
"node-opcua": "2.176.0",
|
|
26
|
+
"node-opcua-address-space": "2.176.0",
|
|
27
|
+
"node-opcua-address-space-for-conformance-testing": "2.176.0",
|
|
28
28
|
"node-opcua-assert": "2.175.6",
|
|
29
|
-
"node-opcua-client-proxy": "2.
|
|
29
|
+
"node-opcua-client-proxy": "2.176.0",
|
|
30
30
|
"node-opcua-crypto": "5.4.0",
|
|
31
|
-
"node-opcua-packet-analyzer": "2.
|
|
31
|
+
"node-opcua-packet-analyzer": "2.176.0",
|
|
32
32
|
"node-opcua-pki": "6.19.0",
|
|
33
|
-
"node-opcua-server-configuration": "2.
|
|
34
|
-
"node-opcua-utils": "2.
|
|
35
|
-
"node-opcua-vendor-diagnostic": "2.
|
|
33
|
+
"node-opcua-server-configuration": "2.176.1",
|
|
34
|
+
"node-opcua-utils": "2.176.0",
|
|
35
|
+
"node-opcua-vendor-diagnostic": "2.176.0",
|
|
36
36
|
"sprintf-js": "^1.1.3",
|
|
37
37
|
"treeify": "^1.1.0",
|
|
38
38
|
"yargs": "15.4.1"
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"internet of things"
|
|
53
53
|
],
|
|
54
54
|
"homepage": "http://node-opcua.github.io/",
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "fc36e66914478084b61b2ac4aeda925bf47a8db8",
|
|
56
56
|
"files": [
|
|
57
57
|
"dist"
|
|
58
58
|
]
|