Jump to content
Sign in to follow this  
MuffettsMan

Can @error be set globally?

Recommended Posts

MuffettsMan

not sure in my noobness i can explain this correctly but i'm trying to see if its possible to save @error to a variable... eh declare it specificly or something so i can always reference it later...

specificly i wrote a simple tcp socket server that detects if a client drops then waits for it to reconnect... all my logic is based off of @error ie:

; If the receive failed with @error then the socket has disconnected
;----------------------------------------------------------------
    If @error Then
        MsgBox(0, "Hmm", "Client Disconnected?!")
        TCPCloseSocket( $ConnectedSocket )
        TCPShutDown()
        Reconnect()
    EndIf

$recv = TCPRecv( $ConnectedSocket, 2048 )
$test = StringLeft($recv, 3) ; THIS BREAKS MY CLIENT DISCONNECT DETECTION >.<

I assume that last line breaks my @error logic because now the @error results are the return of my attempt to do a StringLeft... or anything else deeper in the script... so i need to be able to define a global @error for the socket connection... or i assume there is some better way to approach this completely?


Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites
ResNullius

So something like

Global $SocketConnError = 0
;other script stuff (recieve monitor loop?)
;----------------------------------------------------------------
; If the receive failed with @error then the socket has disconnected
;----------------------------------------------------------------
    If @error Then
        $SocketConnError = 1
        MsgBox(0, "Hmm", "Client Disconnected?!")
        TCPCloseSocket( $ConnectedSocket )
        TCPShutDown()
        Reconnect()
    EndIf

$recv = TCPRecv( $ConnectedSocket, 2048 )
$test = StringLeft($recv, 3)

You just have to remember to set/reset $SocketConnError = 0 somewhere; in you Reconnect() function probably.

Edited by ResNullius

Share this post


Link to post
Share on other sites
MuffettsMan

wow ehh nevermind this is an example of i shouldn't be coding at 3am!


Don't let that status fool you, I am no advanced memeber!

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  

×