|
-
May 3rd, 2010, 06:01 PM
#14
Re: CAsyncSocket and Threads
The use of CAsyncSocket in a separate thread is relatively uncommon, and is ordinarily completely unnecessary. It was for this reason that Dr. Newcomer wrote his article "An MFC Asynchronous Socket Example Done Right" ( http://www.flounder.com/kb192570.htm ):
 Originally Posted by An MFC Asynchronous Socket Example Done Right
There was a recent newsgroup posting about asynchronous sockets in separate threads...
One possible reason to use a separate thread involves servers that must accept many hundreds of connections. But ordinarily (and particularly for clients that establish only a few connections), there is absolutely no reason to use CAsyncSocket in a separate thread. And if you think you have a reason, then CAsyncSocket is probably the wrong architecture anyway (better to use IOCP).
Moreover, if you decide to use CAsyncSocket in a separate thread, the thread must be a UI thread (MFC nomenclature), which has its own message loop, as Dr. Newcomer's article makes abundantly clear.
That being said, the presence of a thread in your case seems unduly complex. I would re-write to keep everything in a single thread.
As for the functions that you need to write, you only need the OnXxx functions, like OnConnect and OnSend and OnReceive. Do NOT write your own Send() or Connect() functions.
Last edited by MikeAThon; May 3rd, 2010 at 06:20 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|