AutoHotkey Community

It is currently May 25th, 2012, 11:47 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: July 20th, 2007, 6:14 am 
Offline

Joined: July 20th, 2007, 3:20 am
Posts: 15
I've edited to fit my own needs the Client side of the pair of socket scripts that everyone seems to be using

To incorporate this into my main 'always running' script, i need the script to not exit when an error occurs or when the socket is closed from the server

what i need to know is if i need to change any of the used variables to their initialized values and if i need to call DllCall("Ws2_32\WSACleanup") after an error or after the server closes the socket or both?

FYI, the purpose of this 'part' of my script is to check my pop3 server for new mail every 2 minutes or so using a timer
while my computer is idle, this will either cease or execute much less frequently...

Q #2, what is the most efficient way someone has come up with to react to my computer going idle and becoming un-idle?

Q #3, is there a more efficient way to get the current script HWND than what i found in the socket script?
Code:
Process, Exist
DetectHiddenWindows On
ScriptMainWindowId := WinExist("ahk_class AutoHotkey ahk_pid " . ErrorLevel)
DetectHiddenWindows Off


O/T: this being my first post here, I feel obliged to express my strong gratitude for this wonderful piece of freeware
i've been using an outdated freeware Girder and (regrettedly) only recently switched to AHK and I have to say that this program has made me very, very happy :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2007, 7:03 am 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
Code:
#persistent
settimer,idletime,60000
return

Idletime:
if (A_TimeIdlePhysical > (10 * 60 * 1000))
msgbox,Idle for ten mins
return

This will check if you are idle

When you say more efficient way of getting the Hwnd, you mean in less lines?

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 20th, 2007, 7:48 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
selyb wrote:
To incorporate this into my main 'always running' script, i need the script to not exit when an error occurs or when the socket is closed from the server

Zed Gecko explains in (a reply in) the thread you linked to how to prevent the script from handling the FD_CLOSE event, or to change which function handles it. As an alternative, it is possible to determine which event was received (in ReceiveData() or whatever function handles the notification message):
Code:
ReceiveData(wParam, lParam)
{
    global FD_CLOSE  ; this is normally set in the init code. if not, uncomment:
    ; FD_CLOSE = 32   ; Received when connection has been closed.
    event := lParam & 0xFFFF  ; MSDN: The low word of lParam specifies the network event that has occurred.

    if (event = FD_CLOSE)  ; connection closed
    { ; do something?
    }
    else  ; could be FD_CONNECT (server only) or FD_READ
    { ; do usual data-reading, etc.
    }
}
I think the script normally does not differentiate between READ and CLOSE - it attempts to read either way, and exits when the read fails.
Quote:
what i need to know is if i need to change any of the used variables to their initialized values
I'm not sure exactly what you're asking, but if you want to reconnect after disconnecting, you'll most likely need to go through the initialization process again. For instance, WSAAsyncSelect() would need to be called to set up the notification message for each socket/connection. "Variables" like FD_READ and FD_CLOSE always have the same value, so needn't be reinitialized. I think the only variables that actually change are the ones whose values are returned by function calls (e.g. "socket".)
Quote:
... and if i need to call DllCall("Ws2_32\WSACleanup") after an error or after the server closes the socket or both?
WSACleanup is normally used to easily close sockets and clean up resources on exit.
MSDN wrote:
Any sockets open when WSACleanup is called are reset and automatically deallocated as if closesocket was called.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2007, 3:17 pm 
Offline

Joined: July 20th, 2007, 3:20 am
Posts: 15
that answered #'s 1 and 2, thanx much :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hcx37b, RoAltmann, Tegno, Yahoo [Bot] and 67 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group