?
Solved

How to disconnect a TCP connection immediately?

Posted on 2003-03-10
2
Medium Priority
?
2,220 Views
Last Modified: 2013-11-13
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
Comment
Question by:wang1st
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Expert Comment

by:aamironline
ID: 8110013
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
 
LVL 5

Accepted Solution

by:
proskig earned 1000 total points
ID: 8110745
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Make the most of your online learning experience.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question