Saturday, 15 June 2013

c# - Correct use of BeginReceive / EndReceive? -



c# - Correct use of BeginReceive / EndReceive? -

to asynchronously receive info socket .net supports symmetrical beginreceive/endreceive calls. phone call beginreceive() start listening , identify callback should called when info arrives. within callback phone call endreceive() extract info , end asynchronous read operation.

i'm writing c#/.net software command industrial equipment. command panel allows users set , initialize equipment , 1 time it's initialized beginreceive() called start listening data. in callback endreceive() used extract data, want resume listening right away think should phone call beginreceive() 1 time again right after doing endreceive(). correct?

if so, there check or test can utilize elsewhere in code know whether beginreceive() has been called don't seek phone call beginreceive() twice in row on same socket, before endreceive() has been called?

the way avoid calling beginreceive() 1 time again before you've called endreceive() set phone call beginreceive() completion callback phone call endreceive(). phone call beginreceive() should not executed there is, of course, 1 create after socket has connected.

edit:

to clear: permitted phone call beginreceive() number of times before receive completion happens. when that, need create sure necessary housekeeping ensure process info in right order (i.e. process buffers in same order in submitted them via beginreceive()).

so above reply not having housekeeping , keeping code simpler.

if ever create subsequent calls beginreceive() in same place calling endreceive(), it's trivial maintain things in order. note though still need right: simplest way ensure receiving buffers in right order not phone call beginreceive() 1 time again until after you've called endreceive() (but still in same method).

c# sockets

No comments:

Post a Comment