Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2243
  • Last Modified:

How to disconnect a TCP connection immediately?

Hi all, I'm writing a multithread web crawler for downloading images from the web. Each thread do the same thing: Connect to a web site, seek images and download them. And certainly it'll block when connecting to the remote server since I use block TCP mothed in each thread. So the problem comes: My program allows users to cancel downloading. It's really a headache when the thread is blocking since I can not notify that thread to end its work when it's  downling or trying to build a connection to the remote server. How can I close all threads when users' trying to cancel downloading? Should I kill the thread in block? That's is the last choice if no other good solution since kill a thread will cause many problems, such as memory leak. Any one gives me a piece of hint? Thanks in advance.
Wang
0
wang1st
Asked:
wang1st
1 Solution
 
aamironlineCommented:
hi,

       just pull the network cable withing less then a second. you will immidly get result...........


ha ha ha ..... just kidding ;)


well you should use closesocket(opensocket) api to close the winsock handle by passing open socket. thats it.


cheers
m aamir maniar

0
 
proskigCommented:
I agree that probably killing threads is not a very good idea, because for example you need to properly save files you have downloaded. As a better idea: you can use WSAEventSelect model and when you do WSAWaitForMultiple event, then you can add your own event. When you want to gracefully close download process, signal that event.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now