break, close all tcp/ip connections at exit

  • Thread starter Thread starter Grzegorz Makarewicz
  • Start date Start date
G

Grzegorz Makarewicz

Hi,

I have multiple uncontrolled (threaded) servers which are waiting in
socket.AcceptSocket.

Is there any method to close these sockets at once/individually ? at
last when invoking Application.Exit ?

mak
 
No, not that I can think of. You can keep a list of them and iterate
through that list when you're ready to exit and call Close() on each one,
which will cause an exception from AcceptSocket(), so you can clean up your
threads.

Paul T.
 
Paul said:
No, not that I can think of. You can keep a list of them and iterate
through that list when you're ready to exit and call Close() on each one,
which will cause an exception from AcceptSocket(), so you can clean up your
threads.

Paul T.

As long as their are managed by application (registered somwhow) so is
no problem - but "corba" endpoints are managed outside of my controll :(.

thanks Paul
PS
instead Application.Exit - use kill(pidof current_app) ?
this is allways an alternative :)
 
You can try just doing an exit of the application, but I think it likely
that the network stack is not going to be in the same state as a result of
that operation as you'd leave it in if you exited more-properly. Maybe it
won't bite you... Terminating the application is *absolutely* no better and
almost certainly worse than a controlled exit.

Paul T.
 
To get around this issue I have used a CustomThreadPool which is a Hash table
and stores objects (connections). So on a connection attempt It gives me a
very detailed object on each connection, what time they connected, how many
packets they have sent/received etc.

So when the server is closed down, I can easily iterate the collection and
close all connections and send messages to them the srver is going down.
 
Back
Top