BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Is ClosedGracefully control neccessary?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
mustafa korkmaz
Guest





PostPosted: Fri Jan 28, 2005 7:26 am    Post subject: Is ClosedGracefully control neccessary? Reply with quote




For Tcp server-client communication some times server disconnect event does not occur..
I am not sure..May be this event occurs after timeout.
For example while the user be connected to server if he shut down his computer suddenly
I think the disconnect event is never called..Or this event may be called after 1-2 minutes.
Which one is true?

So I check all my connection for every 40 seconds.

for each client threads:
try
if gettickcount - TMytype( Athread.data ).lastsendtime > 40000 then
Athread.connection.disconnect;
except
end;
if the server program receives any package from client it sets lastsendtime value with gettickcount.

Is there any wrong idea?
My program must know to any connection actives or not in a short time.
And ondisconnect event must be called.
Other connections are being informed in this event(and some memory free operations).
So must I use ClosedGracefully control for above control?
for each client threads:
try
if ( gettickcount - TMytype( Athread.data ).lastsendtime > 40000 ) or
( Athread.Connection.ClosedGracefully ) then
Athread.connection.disconnect;
except
end;

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Jan 28, 2005 8:06 pm    Post subject: Re: Is ClosedGracefully control neccessary? Reply with quote




"mustafa korkmaz" <mkorkmaz42 (AT) hotmail (DOT) com> wrote


Quote:
For Tcp server-client communication some times server
disconnect event does not occur..

Yes, it is. It may not always happen right away, though, especially if the
client is not disconnecting properly.

Quote:
For example while the user be connected to server if he shut down
his computer suddenly I think the disconnect event is never called..
Or this event may be called after 1-2 minutes. Which one is true?

If the client does not disconnect properly, the underlying socket stack has
no way of knowing that the client is no longer available. As such, it does
not report any errors on the socket until a (usually long, meaning hours)
internal timeout occurs. In the meantime, all reading reports no available
data and all writing is buffered for later transmission. Only when the
socket is eventually invalidated does the stack then report errors for the
socket. Until that happens, Indy has no way of knowing that the socket is
no longer valid, either, this it keeps working on the socket normally. This
is not a bug in Indy. This is just how socket programming works in general.

Quote:
So I check all my connection for every 40 seconds.

That is what you will have to do.

Quote:
My program must know to any connection actives or not in a short time.

Then use short timeouts.

Quote:
And ondisconnect event must be called.

Once the socket is disconnected, whether by the client properly or by you
manually, then OnDisconnect wll be triggered.

Quote:
Other connections are being informed in this event(and some memory
free operations). So must I use ClosedGracefully control for above
control?


No. If ClosedGracefully is True, the socket will be closed automatically
for you.


Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.