Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive packet upload confirmation with WinRT StreamSockets?

I have a WinRT application which performs uploads using StreamSocket and DataWriter. It tracks the time the upload takes and then calculates the throughput.

The issue I am having is that I am getting throughputs much higher than Wireshark shows. This is because my upload loop finishes and takes the ending timestamp before the WinRT framework has actually sent the data to the network layer. I have found no means of receiving confirmation from the framework that the packets have actually made it to the network layer. The DataWriter StoreAsync method only returns the number of bytes you've stored, which I knew before I stored them.

Other frameworks, such as Windows Phone, have a callback in place that gets triggered after your packet is sent and tells you how many bytes you've uploaded. I haven't found any equivalent in WinRT and have had to settle for a loop that records how many bytes I've committed in the StoreAsync function.

Is there a way to get confirmation from the framework of when and how many bytes have actually been sent to the network layer?

UPDATE: I gave @polkduran's suggestions a try, and while they helped alleviate some of the packet loss, I am still experiencing significant packet loss in smaller file uploads (100KB). For larger files (4MB and 10MB), all of the packets are being sent, but the end time is still off by a couple seconds, which skews the throughput calculation significantly (when compared to Wireshark traces). My guess is the callback just slowed down the uploads a bit, rather than providing actual packet upload confirmation.

I'm still looking for a solution to this issue.

EDIT: I created a support ticket with Microsoft about this issue. Their official response is that there is no way in the WinRT framework to confirm that a packet has actually been uploaded.

like image 791
jokeefe Avatar asked Nov 04 '22 03:11

jokeefe


1 Answers

I have not tried but you can assign a handler to the Completed callback property in the DataWriterStoreOperation returned by the StoreAsync method of the DataWritter object.

Or

You can use directly the WriteAsync method from the OutputStream property from your StreamSocket which return a IAsyncOperationWithProgress operation.

like image 152
polkduran Avatar answered Nov 09 '22 12:11

polkduran