Asynchronous Sockets clarification

F

family.sens

i need to know .... if im using Async sockets (using callbacks and
BeginSend()) calls..... can i do way with spawning Threads ?

the way my program works

1. Listen on socket X
2. when connections come in (multiple connections possib), i process
the data, send it to another server, get the data and return it via the
SAME thread that sent the data initially.i was earlier thinking of
doing this

Receive-Process-Send To SErver-Get Data-Return to SOcket Where i
Received It From

process using a different thread....

now im confused, because i read somewhere that the Async method spawns
threads internally....

Question: HOW do i know which socket has sent the data ?

TIA!
 
F

family.sens

Oh , and im Using VS 2003 to do all this .. in case THAT makes any diff
, i havent worked on Whidbey at all so i dunno.
 
M

Markus Stoeger

Question: HOW do i know which socket has sent the data ?

Every socket.BeginXXX method has an "object state" parameter, into which
you can pass any object (like a socket).

When a callback gets called it gets an IAsyncResult as parameter. The
IAsyncResult contains an "object AsyncResult", which is the same thing
you passed to the BeginXXX method.

hth,
Max
 
W

William Stacey [MVP]

You could use sync. If you want to use the same thread: Get connection,
spawn a client thread passing socket. Client thread now blocks on second
server call and returns. You could also use your own thread pool for client
workers. If want to use the same thread, there is no advantage in using
async as the client thread has to block anyway waiting for the server reply
in order to reply to the client.

--
William Stacey [MVP]

|i need to know .... if im using Async sockets (using callbacks and
| BeginSend()) calls..... can i do way with spawning Threads ?
|
| the way my program works
|
| 1. Listen on socket X
| 2. when connections come in (multiple connections possib), i process
| the data, send it to another server, get the data and return it via the
| SAME thread that sent the data initially.i was earlier thinking of
| doing this
|
| Receive-Process-Send To SErver-Get Data-Return to SOcket Where i
| Received It From
|
| process using a different thread....
|
| now im confused, because i read somewhere that the Async method spawns
| threads internally....
|
| Question: HOW do i know which socket has sent the data ?
|
| TIA!
|
 
G

Guest

All of the BeginXXX / EndXXX method signatures automatically use a Threadpool
thread in the background.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top