Sign in to follow this  
Followers 0
tbaror

TCP Ping port error condition and timer

2 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0