2017-01-17 1 views
0

입니다. 현재 두 대의 다른 컴퓨터간에 서버와 클라이언트를 실행하려고합니다. 그러나 서버는 정상적으로 작동하지만 클라이언트는 작동하지 않습니다. 나는 sudo ufw port 4334를 사용하려고했지만 아무 소용이 없다. 누군가 나를 도울 수 있습니까?우분투 포트는 클라이언트를 청취하지 않지만 서버는

/*global require,console,setTimeout */ 
    var opcua = require("node-opcua"); 
    var async = require("async"); 
    var fs = require("fs"); 
    var csv = require("fast-csv"); 
    var sleep = require("system-sleep"); 

    var client = new opcua.OPCUAClient(); 
    var endpointUrl = "opc.tcp://" + require("os").hostname() + ":4334/UA/MyLittleServer"; 


    var the_session, the_subscription; 

    async.series([ 

     // step 1 : connect to 
     function(callback) { 
      client.connect(endpointUrl,function (err) { 
       if(err) { 
        console.log(" cannot connect to endpoint :" , endpointUrl); 
       } else { 
        console.log("connected !"); 
      console.log("Endpoint URL ", endpointUrl); 
       } 
       callback(err); 
      }); 
     }, 

     // step 2 : createSession 
     function(callback) { 
      client.createSession(function(err,session) { 
       if(!err) { 
        the_session = session; 
       } 
       callback(err); 
      }); 
     }, 

     // step 3 : browse 
     function(callback) { 
      the_session.browse("RootFolder", function(err,browse_result){ 
       if(!err) { 
        browse_result[0].references.forEach(function(reference) { 
         console.log(reference.browseName.toString()); 
        }); 
       } 
       callback(err); 
      }); 
     }, 

     // step 4 : read a variable with readVariableValue 
     //function(callback) { 
     // the_session.readVariableValue("ns=2000;s=TEST", function(err,dataValue) { 
     //  if (!err) { 
     //   console.log(" free mem % = " , dataValue.toString()); 
     //  } 
     //  callback(err); 
     // }); 
     //}, 

     // step 4' : read a variable with read 
     //function(callback) { 
     // var max_age = 0; 
     // var nodes_to_read = [ 
     //  { nodeId: "ns=2000;s=TEST", attributeId: opcua.AttributeIds.Value } 
     // ]; 
     // the_session.read(nodes_to_read, max_age, function(err,nodes_to_read,dataValues) { 
     //  if (!err) { 
     //   console.log(" free mem % = " , dataValues[0]); 
     //  } 
     //  callback(err); 
     // }); 
     //}, 


    // function(callback){ 
    //  the_session.readVariableValue("ns=74;s=Dou", function(err,dataValue) { 
    //   if(!err){ 
    //    console.log("Test Success", dataValue.toString()); 
    //   } 
    //   callback(err); 
    //   }); 
    //  }, 
    // 
    // function(callback){ 
    //  the_session.readVariableValue("ns=74;s=Float", function(err,dataValue) { 
    //   if(!err){ 
    //    console.log("Test Success", dataValue.toString()); 
    //   } 
    //   callback(err); 
    //   }); 
    //  }, 
    // 
    // function(callback){ 
    //  the_session.readVariableValue("ns=74;s=String", function(err,dataValue) { 
    //   if(!err){ 
    //    console.log("Test Success", dataValue.toString()); 
    //   } 
    //   callback(err); 
    //   }); 
    //  }, 

    // function(callback){ 
    //  the_session.readVariableValue("ns=1;s=CSV", function(err, dataValue) { 
    //   if(!err){ 
    //    console.log(dataValue.toString()); 
    //    sleep(5000); 
    //   } 
    //   callback(err); 
    //   }); 
    //  }, 

    // function(callback){ 
    //  the_session.readVariableValue("ns=1;s=CSV", function(err, dataValue) { 
    //   if(!err){ 
    //    fs.createReadStream(dataValue.toString()) 
    //    console.log(dataValue.toString()); 
    //    sleep(5000); 
    //     .pipe(csv()) 
    //     .on('data', function(data){ 
    //     console.log(csv); 
    //     sleep(5000); 
    //     }) 
    //     .op('end', function(data){ 
    //     console.log("Read Finish") 
    //     }); 
    //   } 
    //   callback(err); 
    //  }); 
    // }, 





     // step 5: install a subscription and install a monitored item for 10 seconds 
     function(callback) { 

      the_subscription=new opcua.ClientSubscription(the_session,{ 
       requestedPublishingInterval: 1000, 
       requestedLifetimeCount: 10, 
       requestedMaxKeepAliveCount: 2, 
       maxNotificationsPerPublish: 10, 
       publishingEnabled: true, 
       priority: 10 
      }); 

      the_subscription.on("started",function(){ 
       console.log("subscription started for 2 seconds - subscriptionId=",the_subscription.subscriptionId); 
      }).on("keepalive",function(){ 
       console.log("keepalive"); 
      }).on("terminated",function(){ 
       callback(); 
      }); 

      setTimeout(function(){ 
       the_subscription.terminate(); 
      },10000000); 

      // install monitored item 
     var monitoredItem = the_subscription.monitor({ 
       nodeId: opcua.resolveNodeId("ns=2000;s=TEST"), 
       attributeId: opcua.AttributeIds.Value 
      }, 
      { 
       samplingInterval: 100, 
       discardOldest: true, 
       queueSize: 10 
      }, 
      opcua.read_service.TimestampsToReturn.Both 
      ); 
      console.log("-------------------------------------"); 

     monitoredItem.on("changed",function(dataValue){ 
       console.log(" New Data Receive = ",dataValue.value.value); 
      }); 
     }, 

     // close session 
     function(callback) { 
      the_session.close(function(err){ 
       if(err) { 
        console.log("session closed failed ?"); 
       } 
       callback(); 
      }); 
     } 

    ], 
    function(err) { 
     if (err) { 
      console.log(" failure ",err); 
     } else { 
      console.log("done!"); 
     } 
     client.disconnect(function(){}); 
    }) ; 
+0

클라이언트와 서버가 같은 호스트 상에있을 때 (클라이언트 URL이 localhost라고 말한 것)이 작동한다고 가정하면, 그것은 유전자 여야합니다 심각한 네트워크 문제. 고려해야 할 사항 : 루프백 인터페이스에서만 수신하는 서버. 서버 방화벽은 포트 4334로 들어오는 연결을 차단합니다. 클라이언트 방화벽이 나가는 연결을 차단합니다. 또한 클라이언트가받는 정확한 오류 게시에 도움이됩니다. – vagelis

답변

0

올바른 시스템을 가리 키도록 끝점 URL을 편집해야 할 수 있습니다.

예를 들어, 클라이언트가 동일한 컴퓨터에서 실행중인 서버를 처리하려고합니다. 당신의 opcua 서버를 가정

var endpointUrl = "opc.tcp://" + require("os").hostname() + ":4334/UA/MyLittleServer"; 

IP를 192.1.2.3와 기계라는 이름의 ServerMachine 포트 4334에서 실행되고 :

당신은 지정해야합니다

var endpointUrl = "opc.tcp://ServerMachine:4334/UA/MyLittleServer"; 

또는

var endpointUrl = "opc.tcp://192.1.2.3:4334/UA/MyLittleServer"; 
관련 문제