digitalmars.D.learn - eof of socketstream?
Hey guys, is there any way to find the end a socketstream? When I use: MemoryStream ms = new MemoryStream(); while (s.socket().isAlive()) ms.write(s.getc()); I run into an endless loop. The socket doesn't send the size of the data, so I need to know when I received all the data. How can I figure out that I received all data? thx for any help!
Jan 22 2012
Nobody knows how to solve that problem? I tried some other solutions where I ran into the same problem: /* Works as long as bytes available and the length of my buffer is > 1 - doesn't work if the file-size (which is unknown) has a size which is a multiple of the buffer size... for ex. if the buffer has a size of 128 byte and the file size is also 128 bytes long and/or is 512 or similar */ while (true) { uint num = ss.readBlock(buffer.ptr, buffer.length); if (num < buffer.length) break; } /* The following works as long as bytes available on the stream - after reading all bytes, the socket blocks */ while (!ss.eof) { ss.getc(); } /* The same like the solutions before... */ while (true) { string cLine = cast(string) ss.readLine(); if (cLine == "") break; } I hope anyone can solve the problem... I don't think it's a bug. In my opinion it has something to do with blocking sockets, but I'm absolutely over-asked why no solution which I found in some other threads doesn't work...
Jan 25 2012