(asynch tcp client) I'm missing something with this example

  • Thread starter Thread starter David
  • Start date Start date
D

David

http://msdn2.microsoft.com/en-us/library/bew39x2a(VS.80).aspx

I was looking at above link and I just don't see the advantage of this. The
main thread is just stopping and waiting for each of the
connects/sends/receives to complete anyway so it seems to me using the
synchronous methods would be much simpler and equivalent as far as
efficiency/performance in this example? What am I missing here? Is it just
that this example is simply to show the structure of putting the begin/end
asynch calls together and not demonstrating a practical use?

any input on this would be greatly appreciated. A good practical example of
asynchronous tcp client/server would be gold to me right now.
 
HI,

Maybe in this case it like that. It's an example after all.

The point is that with an async you can do other stuff (or at the least no
block the UI) while you transfer the data.
 
Maybe in this case it like that. It's an example after all.

The point is that with an async you can do other stuff (or at the least no
block the UI) while you transfer the data.

It depends on the situation. In the case of a server, I'd say the main
point of async IO is to be able to handle thousands of clients without
the context switches involved in running thousands of threads.

Chris Mullins is the person to ask though :)
 
Jon Skeet said:
It depends on the situation. In the case of a server, I'd say the main
point of async IO is to be able to handle thousands of clients without
the context switches involved in running thousands of threads.

Chris Mullins is the person to ask though :)

The main thread is just a harness for the sample routines. It is not a real
user. One should use asynch I/O when one needs it. For example, when you
want your GUI to be responsive even when the other party fails.

JR
 
The sample is showing you how to do basic async socket programming, but it
is (as you point out) really defeating the purprose by doing so much
waiting.

Async sockets are good for handling lots of sockets very cheaply, and for
helping you not have to create and manage your own threads.

There are a number of better examples that Microsoft has put out. Their
server sample of that same program is a bit better: This creates a server
socket, that just echo's things back to the sender. Pretty straight forward.
http://msdn2.microsoft.com/en-us/library/fx6588te.aspx

There are a ton of examples on CodeProject that use async sockets:
http://www.google.com/search?hl=en&q=Socket+Async+C#+site:codeproject.com&btnG=Search
 
thanks Chris. Its appreciated.

Chris Mullins said:
The sample is showing you how to do basic async socket programming, but it
is (as you point out) really defeating the purprose by doing so much
waiting.

Async sockets are good for handling lots of sockets very cheaply, and for
helping you not have to create and manage your own threads.

There are a number of better examples that Microsoft has put out. Their
server sample of that same program is a bit better: This creates a server
socket, that just echo's things back to the sender. Pretty straight
forward.
http://msdn2.microsoft.com/en-us/library/fx6588te.aspx

There are a ton of examples on CodeProject that use async sockets:
http://www.google.com/search?hl=en&q=Socket+Async+C#+site:codeproject.com&btnG=Search
 
Back
Top