Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to send a message and receive a response using asynchonous sockets in .net. In a function I do the following

1. Send a message thru the socket
2. While(fullresponserecieved)=false, this holds state, this variable turns to true while I receive 0 bytes(or end of message).
3. Then I execute the rest of my function.

I think this is causing a problem with the threads. The thread executing function and the asynchronous socket threads. Is this the correct way to do this? Or should I be using a blocking thread? It may take some time to receive the entire response, up to about 1 minute, I wouldn't want my application to become unresponsive for that period of time.

Thanks,

-ren
Posted

1 solution

In my strong opinion, threads make asynchronous APIs redundant. Asynchronous calls should spawn a thread indirectly anyway, or have equivalent functionality. Using threads with synchronous blocking calls is more straightforward, robust and reliable way.

—SA
 
Share this answer
 
Comments
Member 2542530 8-Nov-11 20:53pm    
Yes, that sounds like a good approach. Do you know any examples?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900