C# Reading and Writing File over Sockets -


i have pretty weird issue right how i'm sending data on sockets. read buffer getting data i'm sending through socket, reason file.write or file.writeasync methods i'm calling not writing bytes, or stopping(i think that's issue) or wrong sockets , how they're being read , written too.

so here snippet of code, keep in mind, both of these on same file different threads.

   byte[] buffer = new byte[1024];    int bytesread;    while((bytesread = receiversocket.receive(buffer)) > 0)             {                 totalbytesread += bytesread;                 //mydownload.write(buffer, 0, bytesread);                 mydownload.writeasync(buffer, 0, bytesread);             } 

the code above receive function download client. keep in mind i'm getting same results regardless of write method use.

and using this:

    byte[] filedata = file.readallbytes(filetosend);     serversocket.sendfile(filetosend); 

i send file filesize: 10560 , retrieve bytes on receive loop, yet when check file after i'm done receives portion so:

totalbytesread

1024

2048

3072 ...

...8192

9216

10240

10560

which means reads data, though in program, it's still stuck inside loop , when close check filesize, it's size 8192, seems me didn't read next 3 socket streams.

i'm @ loss this, there i'm doing wrong? threading issue i'm not aware of?

i figured out answer, locking on my

    while((bytesread = receiversocket.receive(buffer)) > 0) 

due socket waiting on receive, sendfile wouldn't send 0, stuck in while loop, 1 closed while, finished writing file.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -