Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
MessageSecurityMode,
OPCUAClient,
OPCUAClientOptions,
SecurityPolicy,
UserTokenType,
Variant
} from "node-opcua-client";
const connectionStrategy: ConnectionStrategyOptions = {
initialDelay: 1000,
maxRetry: 1
};
const options: OPCUAClientOptions = {
applicationName: "Hello",
connectionStrategy,
securityMode: MessageSecurityMode.None,
// securityPolicy: SecurityPolicy.Basic256Sha256
securityPolicy: SecurityPolicy.None
};
const client = OPCUAClient.create(options);
(async () => {
try {
console.log(" about to connect");
await client.connect("opc.tcp://opcuademo.sterfive.com:26543");
console.log("connected");
client.on("backoff", () => {
console.log("Backoff");
});
try {
const connectionStrategy: ConnectionStrategyOptions = {
initialDelay: 1000,
maxDelay: 20000, // retry every 20 seconds
maxRetry: 2 // maxRetry: 0xFFFFF // we need a large number here
};
const options: OPCUAClientOptions = {
applicationName: "ClientBrowseNextDemo",
connectionStrategy,
endpoint_must_exist: false,
keepSessionAlive: false,
requestedSessionTimeout: 60000, // 1 minute
securityMode: MessageSecurityMode.None,
securityPolicy: SecurityPolicy.None
};
const client = OPCUAClient.create(options);
client.on("backoff", (retry: number, delay: number) => {
console.log("Backoff ", retry, " next attempt in ", delay, "ms");
});
client.on("connection_lost", () => {
console.log("Connection lost");
});
client.on("connection_reestablished", () => {
console.log("Connection re-established");
});
async function main() {
const connectionStrategy: ConnectionStrategyOptions = {
initialDelay: 1000,
maxDelay: 20000, // retry every 20 seconds
maxRetry: 2, // maxRetry: 0xFFFFF // we need a large number here
};
const options: OPCUAClientOptions = {
applicationName: "ClientBrowseNextDemo",
connectionStrategy,
endpoint_must_exist: false,
keepSessionAlive: false,
requestedSessionTimeout: 60000, // 1 minute
securityMode: MessageSecurityMode.None,
securityPolicy: SecurityPolicy.None,
};
const client = OPCUAClient.create(options);
client.on("backoff", (retry: number, delay: number) => {
console.log("Backoff ", retry, " next attempt in ", delay, "ms");
});
client.on("connection_lost", () => {
console.log("Connection lost");
});
client.on("connection_reestablished", () => {
console.log("Connection re-established");
});
async function main() {
const connectionStrategy: ConnectionStrategyOptions = {
initialDelay: 1000,
maxRetry: 1
};
const options: OPCUAClientOptions = {
applicationName: "ClientWithCustomDataTypeSupport",
connectionStrategy,
securityMode: MessageSecurityMode.None,
// securityPolicy: SecurityPolicy.Basic256Sha256
securityPolicy: SecurityPolicy.None
};
const client = OPCUAClient.create(options);
console.log(" about to connect");
await client.connect("opc.tcp://" + os.hostname() + ":48010");
console.log("connected");
client.on("backoff", () => {
console.log("Backoff");
});
const session = await client.createSession();
async function main() {
const connectionStrategy: ConnectionStrategyOptions = {
initialDelay: 1000,
maxRetry: 1
};
const options: OPCUAClientOptions = {
applicationName: "ClientBrowseNextDemo",
connectionStrategy,
securityMode: MessageSecurityMode.None,
securityPolicy: SecurityPolicy.None
};
const client = OPCUAClient.create(options);
await client.connect(endpointUri);
client.on("backoff", () => {
console.log("Backoff");
});
const session = await client.createSession();
const result = await session.call({
inputArguments: [
new Variant({
} from "node-opcua-client";
async function timeout(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
const connectionStrategy: ConnectionStrategyOptions = {
initialDelay: 1000,
maxRetry: 1
};
const options: OPCUAClientOptions = {
applicationName: "HelloSample2",
connectionStrategy,
defaultSecureTokenLifetime: 10000,
keepPendingSessionsOnDisconnect: false,
securityMode: MessageSecurityMode.None,
securityPolicy: SecurityPolicy.None
};
const client = OPCUAClient.create(options);
client.on("backoff", (count: number, delay: number) => {
console.log("backoff ");
});
async function test1() {
try {
await client.connect("opc.tcp://opcuademo.sterfive.com:26543");
const session: ClientSession = await client.createSession({