Re: Joe's AsyncSocket Example
- From: "asellon" <patriot92@xxxxxxx>
- Date: Tue, 25 Mar 2008 11:03:25 -0500
Thanks for the input, but I am certain I want to go this route. In the
design here, the CWinThread has a single call to Send that transfers the
data across the thread boundary and pushesit on the socket. In turn, each
socket, correctly handles the OnReceive call and as the buffer gets data,
the app get notified, instead of some sort of polling mechanism.
Further, the application will be completely custom drawn so I want to
provide as much responsiveness to that as possible
<malachy.moses@xxxxxxxxx> wrote in message
news:b6306f16-0c84-4f26-ae64-15b82dacb38d@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
But remember: the point of Joe's example was how to use CAsyncSocket
correctly when multithreading. In other words, multithreading was the
key; Joe wanted to address the remarkably inept code provided by
Microsoft in their MSDN sample for use of CAsyncSocket in multiple
threads.
It's perfectly fine to use CAsyncSocket in a singly-threaded
application, with the socket code running in the same thread as the
GUI code. In fact, that's the way CAsyncSocket was designed to work.
According to this design, the winsock stack converts network events
into ordinary Windows messages, and the CAsyncSocket class converts
those messages into calls to your virtual overrides of the OnReceive,
OnSend etc functions. Thus, a singly threaded app works just fine, so
long as you are not asking too much for the network activity.
You should ask yourself whether your network code and/or architecture
is so complex that it warrants a multi-threaded design. Frankly, a
simple client with only two simultaneous connections to a server does
not sound like it's complicated enough to warrant the extra
complexities that come with a multi-threaded program (thread
synchronization, data synchronization etc).
On Mar 25, 6:52 am, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:
No, it should be completely symmetric. My example application only
connects to one
server, but that's only because I wanted a simple GUI interface. But as
far as I know,
there's nothing in the code that limits a client in any way.
joe
On Tue, 25 Mar 2008 08:28:34 -0500, "asellon" <patrio...@xxxxxxx> wrote:
Joe,
I have a need to connect a single application to 2 servers. So, I need a
client application that has 2 client sockets. Do you foresee any issues
with using the current clientsocket from your example in this manner? The
plan is to use a little of your server style code and maintain a
DWORDArray
of the thread ids(which will be two of them) and then use the functions
pretty much as is.
I guess the whole point is in the case of using the client socket code,
what
needs to be considered to run two client socket threads in the same
client?
Anything special to consider?
thanks
Andy
Joseph M. Newcomer [MVP]
email: newco...@xxxxxxxxxxxx
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
- Show quoted text -
.
- References:
- Joe's AsyncSocket Example
- From: asellon
- Re: Joe's AsyncSocket Example
- From: Joseph M . Newcomer
- Re: Joe's AsyncSocket Example
- From: malachy . moses
- Joe's AsyncSocket Example
- Prev by Date: Re: Recipe for those who are in diet
- Next by Date: Re: Joe's AsyncSocket Example
- Previous by thread: Re: Joe's AsyncSocket Example
- Next by thread: Re: Joe's AsyncSocket Example
- Index(es):
Relevant Pages
|