c# - Asynchronously send / receive fixed amount of data using tcp socket -
in application asynchronous communication on tcp socket.
i don't fact send , receive operations (sync or async) of socket class allowed finish before requested number of bytes transmitted. example: when want read x bytes socket, don't want care how many read operations needed achieve (in application logic). want notified when it's finished (or when error occured).
it nice have beginsendfixed, endsendfixed, beginreceivefixed , endreceivefixed. behave beginsend, endsend, beginreceive, endreceive, not call callback before requested number of bytes transmitted.
i'm thinking implementing myself, based on:
http://msdn.microsoft.com/en-us/magazine/cc163467.aspx
in dotaskhelper function call many (synchronous) send or receive until data transmitted.
is way go or there different (better) way hide need multiple sends / receives application logic?
i recommend using taskcompletionsource
class this. has advantage of not burning thread waiting i/o. easier wrap existing (asynchronous) apis task
s first, , create api using taskcompletionsource
.
note taskcompletionsource
added in .net 4. if you're not on platform yet, recommend marshaling completion routines ui thread (which can done using event-based asynchronous pattern socket wrappers in nito.async.sockets), , putting them through parser specific protocol (an example of on blog).
Comments
Post a Comment