Jump to content

TCP Ping port error condition and timer


tbaror
 Share

Recommended Posts

Helllo,

I am writing kind of TCP port ping function , i want to add timer for measuring latency.

The issue is when the timer var is enabled i don't get any feedback if error is occurred in case address or port is not available/timeout.

error condition works only if i comment the timer procedures, please advice how to make this works including timers.

Thanks in advanced.

#include <GUIConstantsEx.au3>


Tcp_ping()

Func Tcp_ping()




Local $ConnectedSocket, $szData
Local $szIPADDRESS = "ip-test"
Local $nPORT = 445

    ; Start The TCP Services
    ;==============================================
    TCPStartup()

    ; Initialize a variable to represent a connection
    ;==============================================
    $ConnectedSocket = -1

    ;Attempt to connect to SERVER at its IP and PORT 33891
    ;=======================================================
    
$TcBegin = TimerInit()
    $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)
        
             $TCdif = TimerDiff($TcBegin)

    If @error Then
        
        MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
        
    Else
        
        MsgBox(1, "OK", "TCPConnect : "& $TCdif)
        
    EndIf
EndFunc   ;==>Example
Link to comment
Share on other sites

You are testing the state of @error as returned by the TimerDiff() function. Either save @error to a variable, or test it, right after TCPConnect() and before executing any other functions.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...