On Thursday, July 31, 2003, at 08:55 PM, Björnke von Gierke wrote:
I use read socket to access a pop3 server (email) I need to repeat certain commands several times. How can I make them non-blocking while still repeating them? I just don't get it :(
Normally when you read from a socket in a repeat loop you want blocking and would not use 'with message'. You might want to make sure all is working well with blocking before making a non-blocking version.
If you are concerned that your handler (which may cause confusion if named 'handler') is taking a long time and keeping you or Revolution from doing anything else, you may want to take another approach. You want non-blocking and 'with message'.
repeat with x = 1 to (the second word of theData) --number of messages-- I assume 'theMessage' means 'it'.
write ( "TOP" && x && "0" & crlf ) to socket server & ":110" --TOP 0 =get only headers
read from socket server & ":110" until crlf & "." & crlf --should be non-blocking but isn't
if theMessage contains "Reply-To: [EMAIL PROTECTED]" then
put x & "," after theList --gather all runrev messages end if
Sarah or Shao Sean can better comment on whether this is good POP3.
The equivalent using 'read ... with message' is below. This off the top of my head, so you might need to make adjustments. The handler startGettingHeaders will get the headers based on its parameter and sor it away in the headerList. Error handling is ignored to keep this simple.
local pop3socketID local currentRecord local lastRecord local headerList
on startGettingHeaders numberOfMessages put numberOfMessages into lastRecord put 1 into currentRecord put empty into headerList queryHeader end startGettingHeaders
on queryHeader
write ("TOP" && currentRecord && "0" & CRLF) to socket pop3socketID
read from socket pop3socketID until CRLF & "." & CRLF with message "processHeader"
end queryHeader
on processHeader socketID, headerData
if headerData contains "Reply-To: [EMAIL PROTECTED]" then
put currentRecord & "," after headerList
end if
add 1 to currentRecord
if currentRecord <= lastRecord then
queryHeader
else
-- process header list (or send a message to process it)
end if
end processHeader
Eventually you will want to write handlers for socketClosed, socketError and socketTimeout and examine the result on write and read.
Dar Scott
************************************************************************ ****
Dar Scott Consulting http://www.swcp.com/dsc/ Programming Services
************************************************************************ ****
_______________________________________________
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution