当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ClientSession.close方法代码示例

本文整理汇总了TypeScript中node-opcua.ClientSession.close方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ClientSession.close方法的具体用法?TypeScript ClientSession.close怎么用?TypeScript ClientSession.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在node-opcua.ClientSession的用法示例。


在下文中一共展示了ClientSession.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: setTimeout

 setTimeout(async () => {
     console.log("time out => shutting down ");
     if (!the_subscription) {
         return resolve();
     }
     if (the_subscription) {
         const s = the_subscription;
         the_subscription = null;
         await s.terminate();
         await the_session.close();
         await client.disconnect();
         console.log(" Done ");
         process.exit(0);
     }
 }, timeout);
开发者ID:node-opcua,项目名称:node-opcua,代码行数:15,代码来源:simple_client.ts

示例2: async

process.on("SIGINT", async () => {

    console.log(" user interruption ...");

    user_interruption_count += 1;
    if (user_interruption_count >= 3) {
        process.exit(1);
    }
    if (the_subscription) {
        console.log(chalk.red.bold(" Received client interruption from user "));
        console.log(chalk.red.bold(" shutting down ..."));
        const subscription = the_subscription;
        the_subscription = null;;
        await subscription.terminate();
        await the_session.close();
        await client.disconnect();
        process.exit(0);
    }
});
开发者ID:node-opcua,项目名称:node-opcua,代码行数:19,代码来源:simple_client.ts

示例3: main


//.........这里部分代码省略.........
        "LastSeverity",
        "Comment",
        "ClientUserId",

        // AcknowledgeConditionType
        "AckedState",
        "ConfirmedState",

        // AlarmConditionType
        "ActiveState",
        "InputNode",
        "SuppressedState",

        "HighLimit",
        "LowLimit",
        "HighHighLimit",
        "LowLowLimit",

        "Value"
    ];

    const eventFilter = constructEventFilter(fields, [
        resolveNodeId("ConditionType")
    ]);

    const event_monitoringItem = ClientMonitoredItem.create(
      the_subscription,
      {
          attributeId: AttributeIds.EventNotifier,
          nodeId: serverObjectId
      },
      {
          discardOldest: true,
          filter: eventFilter,
          queueSize: 100000
      }
    );

    event_monitoringItem.on("initialized", () => {
        console.log("event_monitoringItem initialized");
    });

    event_monitoringItem.on("changed", (eventFields: Variant[]) => {
        dumpEvent(the_session, fields, eventFields);
    });
    event_monitoringItem.on("err", (err_message: string) => {
        console.log(chalk.red("event_monitoringItem ", baseEventTypeId, " ERROR"), err_message);
    });

    console.log("--------------------------------------------- Monitoring alarms");
    const alarmNodeId = coerceNodeId("ns=2;s=1:Colours/EastTank?Green");
    await monitorAlarm(the_subscription, alarmNodeId);

    console.log("Starting timer ", timeout);
    if (timeout > 0) {

        // simulate a connection break at t =timeout/2
        // new Promise((resolve) => {
        setTimeout(() => {

            console.log(chalk.red("  -------------------------------------------------------------------- "));
            console.log(chalk.red("  --                               SIMULATE CONNECTION BREAK        -- "));
            console.log(chalk.red("  -------------------------------------------------------------------- "));
            const socket = (client as any)._secureChannel._transport._socket;
            socket.end();
            socket.emit("error", new Error("ECONNRESET"));
        }, timeout / 2.0);
        // });

        await new Promise((resolve) => {
            setTimeout(async () => {
                console.log("time out => shutting down ");
                if (!the_subscription) {
                    return resolve();
                }
                if (the_subscription) {
                    const s = the_subscription;
                    the_subscription = null;
                    await s.terminate();
                    await the_session.close();
                    await client.disconnect();
                    console.log(" Done ");
                    process.exit(0);
                }
            }, timeout);
        });

    }

    console.log(" closing session");
    await the_session.close();
    console.log(" session closed");

    console.log(" Calling disconnect");
    await client.disconnect();

    console.log(chalk.cyan(" disconnected"));

    console.log("success !!   ");
}
开发者ID:node-opcua,项目名称:node-opcua,代码行数:101,代码来源:simple_client.ts


注:本文中的node-opcua.ClientSession.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。