Note that there are some explanatory texts on larger screens.

plurals
  1. POHow much bytes has been sent over a specific socket?
    primarykey
    data
    text
    <p>I'm building a client in <code>C#</code> that comunicates with a server in <code>Python</code>. The client sends files to the server using the <code>Socket.send()</code> method, and uses threads to be able to send multiple files asynchronously using a <code>BackgroundWorker</code>: </p> <pre><code>private void initializeSenderDaemon() { senderDaemon = new BackgroundWorker { WorkerReportsProgress = true, }; senderDaemon.DoWork += sendFile; } </code></pre> <p>When some condition is met, the <code>RunWorkerAsync()</code> method is called and a file is sent</p> <p>Both client and the server acknowledge on the size of the file before begin the transfer</p> <p>I want to be able to track how much of the file has been sent from client side</p> <p>I've though about something like this <strong>CONCEPTUAL CODE, I KNOW THAT IT DOESN'T WORK</strong></p> <pre><code>byte[] fileContents = File.ReadAllBytes(path); // original file byte[] chunk = null; // auxiliar variable, declared outside of the loop for simplicity sake int chunkSize = fileContents.Length / 100; // we will asume that the file length is a multiplier of 100 for simplicity sake for (int i = 0; i &lt; 100; i++) { chunk = new byte[chunkSize]; Array.Copy(fileContents, i * chunkSize, chunk, i * chunkSize, chunkSize); // Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length); s.Send(chunk); reportProgress(i); } reportProgress(100); </code></pre> <p>There are obvious issues with that code, but I wrote it just to explain what I want to do</p> <p>¿How can I track how many bytes has been already sent to the server for one specific file? ¿There is any way to do it without relying on workarounds? ¿Should I use other method from the socket class?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload