473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1071
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Corne Oosthuizen | last post by:
I'm writing a Telnet Server application using Asynchronous sockets. I spawn a listener thread to handel incomming connections and create a separate client socket for each new connection. I...
3
by: Matthew King | last post by:
Hi all I've written a asynchronous socket client class, but i've found that in order to consume it I have to use events, and cannot simply for example SocketClient client = new...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
9
by: Michael Lindsey | last post by:
I need to write a server app to send images to client GUIs that are outside of the server's domain. The client will have the file system path to the image but can not access the file system. I am...
4
by: taskswap | last post by:
I have a legacy application written in C that I'm trying to convert to C#. It processes a very large amount of data from many clients (actually, upstream servers - this is a mux) simultaneously. ...
4
by: Macca | last post by:
I am writing an application that uses asynchronous sockets to get data over ethernet from embedded devices, up to 30 concurrent devices.(These devices are written in C). My application...
2
by: Ronodev.Sen | last post by:
the way my program needs to go is -- 1) open a socket and listen on it 2) moment a client connects to the socket - process some data (by sending it to another machine), get the result and send...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
2
by: Nicolas Le Gland | last post by:
Hello everyone here. This is my first post in this newsgroup, I hope I won't be to much off-topic. Feel free to redirect me to any better group. I am getting strange timing issues when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.