Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1) What would be the advantages of using non-blocking sockets over blocking sockets?
2) What would be the advatages of using beginSend/beingReceive with a blocking socket ?

I am building a client-server chat applicaition with blocking sockets ..
now what im trying to grasp would be the advantages of using non-blocking sockets or asyncrounous methods:
- If I use non-blocking i still need to loop threw the message to send it all..So with blocking sockets it would block and maybe not half to loop at all threw the send operaition
- If I use begin send, the endsend blocks until done (so whats the point?) plus in order to check if all the packet was sent i need to check it in the asynccallback method and recursivly call it again if necessary,which seemes like a lot of overhead when as I understand the callback is done on the threadpool so the message would have to wait until a thread is available in order to send it, instead I got a thread looping endlessly and sending messages.
I could see the advantages of using beingSend / beginReceive for the reponsiveness of the program but I can't seem to find a way to return the bytes sent from it ?
It returns IAsyncResual but is there a way to return the bytes that where sent threw the result ?
Updated 10-Feb-11 21:44pm

1 solution

You would normally send all the data with beginSend and then only when you reach a point where you cannot proceed unless all the data has been sent then and only then you call endSend for each of the packets sent. This way you are free to do other tasks while the Send is taking place.

If you must know which packet caused an error you need to use the objectState to hold the information that points to the packet.
Share this answer

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