|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
BeginSend question about sent bytesI was hoping someone could help me understand the number of bytes sent
if I am using BeginSend. Let's assume I send 100 bytes of data using BeginSend. In my async callback, if I call EndSend it will return me the number of bytes that were actually sent. My question is under what circumstances will the number of bytes reported when calling EndSend not match the number of bytes I wanted to send. So, EndSend says it sent 50 bytes and I wanted to send 100 bytes. If the case is that EndSend reports only 50 bytes were sent, do I need to resend the remaining 50 bytes again by calling BeginSend again with those 50 bytes? appz***@gmail.com wrote:
Show quote > I was hoping someone could help me understand the number of bytes sent Theoretically, yes, you need to loop and keep sending slices of the> if I am using BeginSend. > > Let's assume I send 100 bytes of data using BeginSend. In my async > callback, if I call EndSend it will return me the number of bytes that > were actually sent. > > My question is under what circumstances will the number of bytes > reported when calling EndSend not match the number of bytes I wanted to > send. So, EndSend says it sent 50 bytes and I wanted to send 100 > bytes. > > If the case is that EndSend reports only 50 bytes were sent, do I need > to resend the remaining 50 bytes again by calling BeginSend again with > those 50 bytes? array until it's all sent. However, I note that NetworkStream, which wraps Socket's Send and Receive, doesn't care about the return value from Send / EndSend. If NetworkStream's implementation is correct, then you don't need to iterate. -- Barry Thanks Barry,
Is there anything I need to assume about those 50 bytes that did not get sent? If initially I sent 100 bytes but the EndSend reports only 50 bytes -- what happened to those 50 missing bytes? Barry Kelly wrote: Show quote > appz***@gmail.com wrote: > > > I was hoping someone could help me understand the number of bytes sent > > if I am using BeginSend. > > > > Let's assume I send 100 bytes of data using BeginSend. In my async > > callback, if I call EndSend it will return me the number of bytes that > > were actually sent. > > > > My question is under what circumstances will the number of bytes > > reported when calling EndSend not match the number of bytes I wanted to > > send. So, EndSend says it sent 50 bytes and I wanted to send 100 > > bytes. > > > > If the case is that EndSend reports only 50 bytes were sent, do I need > > to resend the remaining 50 bytes again by calling BeginSend again with > > those 50 bytes? > > Theoretically, yes, you need to loop and keep sending slices of the > array until it's all sent. However, I note that NetworkStream, which > wraps Socket's Send and Receive, doesn't care about the return value > from Send / EndSend. If NetworkStream's implementation is correct, then > you don't need to iterate. > > -- Barry > > -- > http://barrkel.blogspot.com/ appz***@gmail.com wrote:
> Thanks Barry, Did you actually see that result? If you did, then that indicates that> > Is there anything I need to assume about those 50 bytes that did not > get sent? If initially I sent 100 bytes but the EndSend reports only > 50 bytes -- what happened to those 50 missing bytes? NetworkStream's implementation is in error. -- Barry Thanks to everyone who has responded.....
To answer your question, I have not actually seen this. I was just curious on all the different cases I would need to handle since I am writing a client/server application. However, from another forums posting, someone kindly pointed me at the MSDN documentation (which I should've read more carefully and I would've gotten my answer) It basically states, that it will block until SOME of the buffer was sent...the keyword being some which means if BeginSend only sent 50 bytes of the 100 bytes I requested I would have to requeue the remaining 50 bytes that were unsent. >From MSDN, the EndSend method: If you are using a connectionless protocol, EndSend will block untilthe datagram is sent. If you are using a connection-oriented protocol, EndSend will block until some of the buffer was sent. If the return value from EndSend indicates that the buffer was not completely sent, call the BeginSend method again, modifying the buffer to hold the unsent data. There is no guarantee that the data you send will appear on the network immediately. To increase network efficiency, the underlying system may delay transmission until a significant amount of outgoing data is collected. A successful completion of the BeginSend method means that the underlying system has had room to buffer your data for a network send. Barry Kelly wrote: Show quote > appz***@gmail.com wrote: > > > Thanks Barry, > > > > Is there anything I need to assume about those 50 bytes that did not > > get sent? If initially I sent 100 bytes but the EndSend reports only > > 50 bytes -- what happened to those 50 missing bytes? > > Did you actually see that result? If you did, then that indicates that > NetworkStream's implementation is in error. > > -- Barry > > -- > http://barrkel.blogspot.com/ I am kind of curious if you have actually seen this as well.
Cheers, Greg <appz***@gmail.com> wrote in message Show quote news:1154561646.578292.327610@p79g2000cwp.googlegroups.com... > Thanks Barry, > > Is there anything I need to assume about those 50 bytes that did not > get sent? If initially I sent 100 bytes but the EndSend reports only > 50 bytes -- what happened to those 50 missing bytes? > > > Barry Kelly wrote: >> appz***@gmail.com wrote: >> >> > I was hoping someone could help me understand the number of bytes sent >> > if I am using BeginSend. >> > >> > Let's assume I send 100 bytes of data using BeginSend. In my async >> > callback, if I call EndSend it will return me the number of bytes that >> > were actually sent. >> > >> > My question is under what circumstances will the number of bytes >> > reported when calling EndSend not match the number of bytes I wanted to >> > send. So, EndSend says it sent 50 bytes and I wanted to send 100 >> > bytes. >> > >> > If the case is that EndSend reports only 50 bytes were sent, do I need >> > to resend the remaining 50 bytes again by calling BeginSend again with >> > those 50 bytes? >> >> Theoretically, yes, you need to loop and keep sending slices of the >> array until it's all sent. However, I note that NetworkStream, which >> wraps Socket's Send and Receive, doesn't care about the return value >> from Send / EndSend. If NetworkStream's implementation is correct, then >> you don't need to iterate. >> >> -- Barry >> >> -- >> http://barrkel.blogspot.com/ > Greg Young wrote:
> I am kind of curious if you have actually seen this as well. I have never seen this happen either. The docs for BeginSend say the following: [...] and will block on EndSend _until the Socket sends the number of bytes requested_ or throws an exception. Max |
|||||||||||||||||||||||