Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to wait until stream write is done
    primarykey
    data
    text
    <p>I have a server app that listens for connections on port 8888. I am also creating the client application. It is a simple application the only hard thing about it is managing multiple connections. so I just need to send files between computers so the way I do that, I don't know if it is wright but it works maybe you guys can correct me. here is my algorithm when sending the file:</p> <pre><code>NetworkStream stream = \\ initialize it while(someCondition) { // first I open the file for reading and read chunks of it byte[] chunk = fileRead(file, indexStart, indexEnd) // I have a similar method this is just to illustate my point stream.Write(chunk, \\other params) // since I often send large files it will be nice if I can wait here // until the stream.Write is done. when debuging this the while loop // executes several times then it waits. } </code></pre> <p>and on the other side I read bytes from that stream and write it to a file.</p> <p>I also need to wait sometimes because I send multiple files and I want to make sure that the first file has been sent before moving to the next. I know I can solve this by using the stream.Read method once the transfer has been done. and sending data back from the client. but sometimes I believe it will be helpful to know when the stream.write is done.</p> <hr> <p>Edit</p> <p>ok so based on your answers I can for example send to the client the number of bytes that I am planing to send. and once the client recives that many bytes it means it is done. But my question is if this is efficient. I mean doing something like</p> <p>on the server:</p> <p>writing data "sending the file length"</p> <p>read data "check to see if the client received the length" (expecting a string ok for example)</p> <p>write data "tel the client the name of the file"</p> <p>read data "check to see if the client recived the name of the file"</p> <p>write data "start sending chuncks of the file"</p> <p>read data "wait until client replies with the string ok for example"</p>
    singulars
    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.
    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