Re: Joe's AsyncSocket Example



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 -


.



Relevant Pages

  • Re: Socket Problem - No data after accept
    ... there is a good article about use of CAsyncSocket in MSDN ... 'MFCSocs.exe Avoids Two Common MFC Socket Mistakes' ... There is a server listen class and server accept class.. ... When client disconnects 'Server Accept' class gets OnClose notification ...
    (microsoft.public.vc.mfc)
  • Re: need to know about a concurrent server
    ... so that in essence each client has its own server. ... are many design alternatives for concurrent server, ... regarding the filedescriptor obtained during the socket call to a new ...
    (comp.unix.programmer)
  • Re: better design pattern for threading in C/S
    ... I spend pretty much all day, every day, working on a fancy .Net socket ... The model you're looking to use (one thread per client) is good for a few ... I am happy both of you mention the design paten for threading. ... Hz CPU, 512M-1G server handle it? ...
    (microsoft.public.dotnet.languages.csharp)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #3]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... kernel socket family. ... presentation side is left to the client. ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)