[twsocket] SmtpClient and aborting connection

2007-05-14 Thread Markus Humm
Hello,

I finally got it working now by using (and somewhat enhancing) that 
thread approach.

I've left out the cancelling on long lasting connection attempts right 
now, maybe I add it later and I think I might want to do it on shutdown 
as well.

Greetings

Markus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] SmtpClient and aborting connection

2007-05-12 Thread Markus Humm
Hello,

I#ve a new idea and would like some expert opinions about it before 
wasting time on it:

what if I put the e-mail sending in a seperate thread where the 
SmptCLient is bound to the thread (execute)? So it would have its own 
message loop which hopefully wouldn't interfere with the rest of the 
com-server.

The only thing are the test and the other synchronously sending method 
which should return success or not and shutting down the com-server 
might be another problem.

Btw. and off topic: why is there a initialization method in the 
automation server you can override but no finalization? So you never 
know within the com server when it's time to finish/clean up, right?

Greetings

Markus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] SmtpClient and aborting connection

2007-05-11 Thread Markus Humm
Hello,

my COM server goes havoc when the e-mail has been sent. If the client 
calls some simple functions which normally would only read something 
from the database and return the value they fail instead. Functions 
which aren't really interdependant or so.

I'm wondering now why. It also happens with my printing code as it 
seems. So my guess now is that it's related that both are (at least this 
is what I think) within the context of a TWSocket's OnDataAvailable.
Could it be that the message handling for the e-mailing etc. can cause 
this? If yes, how to circumvent this?

Greetings

Markus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] SmtpClient and aborting connection

2007-05-10 Thread Wilfried Mestdagh
Hello Markus,

You dont have to loop. Just set a Timer and Connect, that's all. You can
disable the Timer in OnSessionConnected. If timer expires just call
Abort. When OnSessionClosed is called set a flag. When OnRequestDone is
called and session is closed start your next connection (depending on
success or not what you can set in in one of the events).

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] SmtpClient and aborting connection

2007-05-10 Thread Markus Humm
Hello,

I've still or even worse trouble with this e-mail sending. maybe I 
should explain it more in detail what my environment is and what I want
to do.

Okay I have this:

COM Client - COM-Server - ICS SmtpClient
  |
   Other application connected via TWSocket (TCP)

The com server provides 3 functions for sending e-mails, one is used 
internally triggered by certain events sent by the other application.

The two methods for sending e-mails (one for a testmail for testing the 
connection) the other for sending something specific shall send the 
e-mail and return whether this was successfull or not. If the sending 
takes more that a certain time it shall be aborted and counted as 
unsuccessfull.

Sending is done in a loop over a list possibly containing more that one 
e-mail server address to that if the first fails the second will be 
tried etc.

After the connect I've this here:

 t:=GetTickCount;
 while ((isemail_connection = true) and (mailerror = 0)) and
   (((GettickCount = t) and (GetTickCount-t  timeout)) xor
((GettickCount  t) and (t-GetTickCount  timeout))) do
 begin
   sleep(10);
   Application.ProcessMessages;
 end;

 if (mailerror  0) or (isemail_connection = true) then
 begin
   try
 datenmodul.SmtpCli.CtrlSocket.Close;
   except
   end;
 end
 else
 begin

   try
 if datenmodul.SmtpCli.Connected then datenmodul.SmtpCli.Quit;
   except
   end;


It shall wait for either the timeout or the finish of the e-mail sending 
process. In the OnRequestDone I've nearly 100% identical code to your 
mail sending excample (the all in one demo) except that the screen 
output is missing, the case is put into a try/except and the 10004 error 
won't lead to a abort of the eventhandler. The handler will set the 
isemail_connection flag when the quit stage is arrived and will set 
mailerror to the errorcode and leave the handler if there is some error.

I also want the com server to handle the communication to that other 
program (not it's client) and process (at least partially) the data he 
gets from it. Unfortunatelly he can raise the event which also triggers 
a mail sending operation. And then I think the trouble starts. I've 
implemented there another loop which waits if a mail is currently sent 
on either the completion (because the same function and thus SmtpClient 
instance) will be user or a timeout. The waiting loop is similar to the 
one above. If the mailserver can be reached, all seems to be well, but 
if I give a non reachable one it miserably fails and the COM-server 
starts to do weired things!

Have you any hints for me? I want the mailing to be partially blocking
to be able to handle the other communication but timely tell the user 
whether seinding was ok or not. And what happens if sending takes place 
and the program get's closed?

Greetings

Markus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] SmtpClient and aborting connection

2007-05-10 Thread Markus Humm
Hello,

Wilfried suggested today that I should use a timer. Basically a good 
idea, but how to do? The com-server's function should send the mail and 
either return sort of true if successfull or false if not (it actually 
would return the mail server's address or a empty string if not 
successfull). How to do this fashion with the timer based approach?

Greetings

Markus

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] SmtpClient and aborting connection

2007-05-09 Thread Markus Humm
Hello,

I'm using your SmtpClient component for sending e-mails.
I'm trying to built in a failover in my application so that if the first 
configured mail server can't be reached a second etc. will be tried.

The problem is now that I like to cancel the connect if it takes too long.

   timeout:=timeout+text.Count*10;

   for i := 0 to length(emailservers) - 1 do
   begin
 with datenmodul.SmtpCli do
 begin

   try
 // setup e-mail parameters like server and content

 mailerror:=0;
 mailerrortext:='';
 isemail_connection:=true;
 Connect;
   except
 mailerror:=1;
 mailerrortext:=ErrorMessage;

 try
   datenmodul.SmtpCli.Quit;
 except
 end;

 continue;
   end;
 end;

 // wait for timeout or success
 t:=GetTickCount;
 while ((isemail_connection = true) and (mailerror = 0)) and
   (((GettickCount = t) and (GetTickCount-t  timeout)) xor
((GettickCount  t) and (t-GetTickCount  timeout))) do
 begin
   sleep(10);
   Application.ProcessMessages;
 end;

 // in case of error disconnect asap
 if (mailerror  0) or (isemail_connection = true) then
 begin
   try
 // datenmodul.SmtpCli.Abort; doesn't work better!
 datenmodul.SmtpCli.CtrlSocket.cose;
   except
   end;
 end
 else
 begin
   try
 if datenmodul.SmtpCli.Connected then datenmodul.SmtpCli.Abort;
   except
   end;

   break;
 end;
   end;

The OnRequestDone is nearly your demo code (the output has been disabled 
and the case has been packed into a try/except block.

I do get 10004 errors or component not ready. It works now since I 
packed it into try/except blocks but I wonder if this will make further 
problems. The problems only occur if the first e-mailserver is bot 
reachable and the connection has to be cancelled.

This is in a normal function which makes it blocking for the direct 
caller but since it's part of a COM-server the COM server could do some 
things internally while trying to send this e-mail.

Greetings

Markus

PS: somebody should document this component in the wiki, obviously not 
me! ;-)
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] SmtpClient and aborting connection

2007-05-09 Thread Angus Robertson - Magenta Systems Ltd
 The problem is now that I like to cancel the connect if it takes 
 too long.

Essentially, you have no control over how long connect takes to time out.
There are registry settings relating to TCP attempts and retry delays,
but messing with them is dangerous and unpredictable, and effects all
Windows applications.  The default timeout is usually about 40 seconds,
if I remember correctly. 

I always ping servers first before connecting to them, that way you can
set a timeout of a few seconds before trying the next one in the list.
Ping will not fail if the server is running, but nothing is listening on
the port, but then you should get a much shorter timeout.  

My threaded ping works asynchronously very nicely, you put the actual
connection attempt or ping next server code in the event that's called on
successful ping or timeout. MagIpLog on the same page illustrates ping
before connection, and reconnection on lost connection. 

http://www.magsys.co.uk/delphi/magics.asp

Angus


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be