Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
_server=127.0.0.1, _port=443, timeout=540000, errorMessage=OE not running
JavaScript
//Validates that a TCPI port is open
//@_server: The IP address of server
//@_port: The port to be checked
//@timeout: The time to wait for the open port.
//@errorMessage: The message to log if the ip/port does not connect in 
//              the specified amount of time.
function CheckPort(_server,_port,timeout,errorMessage){ 
          var address, port, socket, broadcast, endpoint, connectResult;  
          var binaryRxData;    address = _server;  
          port = _port;   
          socket = dotNET.System_Net_Sockets.Socket.zctor(
                  dotNET.System_Net_Sockets.AddressFamily.InterNetwork,        
                  dotNET.System_Net_Sockets.SocketType.Stream,         
                  dotNET.System_Net_Sockets.ProtocolType.Tcp);  
          broadcast = dotNET.System_Net.IPAddress.Parse(address);  
          endpoint = dotNET.System_Net.IPEndPoint.zctor_2(broadcast, port);
          
          //Variable to hold the total time we are waiting
          var totalWaitTimeout = 0;
          
          connectResult = false ;
          //Until specified object disappears/gets disposed
          while(1)
          {
            //Delays the test execution for the specified time period.
            Delay(500);
            //Recalculate the total time we are waiting
            totalWaitTimeout = totalWaitTimeout + 500;

            try
                 {    socket.Connect(endpoint);
                      connectResult = true;    // it is connected to the port
                  }  
            catch(exception)     
                 {    
                    // do nothing    
                 }
                 
                 
                
            if(totalWaitTimeout > timeout)
            {
              Log.Error(errorMessage, "");
              break;
            }
            
            if(connectResult)
            {
              socket.Disconnect(true);
              break;
            }
            
          }            
          return ; 
}

Error Received:

'dotNET.System_Net_Sockets.Socket' is null or not an object
Error location:
Unit: "InstallerSuite\14221\Script\Common_Validation"
Line: 93 Column: 11.
Posted
Updated 24-Oct-12 8:22am
v2
Comments
Sergey Alexandrovich Kryukov 24-Oct-12 17:02pm    
In what line? Well, anyway, you simply did not initialize this object.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900