471,330 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Asynchronous Sockets clarification

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!

Feb 19 '06 #1
4 1013
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.

Feb 19 '06 #2
fa*********@gmail.com wrote:
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
Feb 19 '06 #3
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]

<fa*********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
|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!
|
Feb 19 '06 #4
All of the BeginXXX / EndXXX method signatures automatically use a Threadpool
thread in the background.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"fa*********@gmail.com" wrote:
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!

Feb 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Corne Oosthuizen | last post: by
3 posts views Thread by Matthew King | last post: by
4 posts views Thread by Matthew Groch | last post: by
9 posts views Thread by Michael Lindsey | last post: by
4 posts views Thread by taskswap | last post: by
4 posts views Thread by Macca | last post: by
4 posts views Thread by Engineerik | last post: by
2 posts views Thread by Nicolas Le Gland | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.