//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 ; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)