N
Neil Saunders via .NET 247
Hello everybody, I'm hoping that somebody will be able to help mebefore I cross the bridge of absolute insanity.
I've recently started to teach myself C#, and to begin with Ihave aimed to write a simple client/server system whereby theserver can request a thumbnail of the clients screen to betransmitted back. After brushing up on my windows GDI knowledge,the system quite happily snaps the screen, usesImage.GetThumbnail to shrink it, and then saves this to aMemoryStream, which is then transmitted back to the Server.Everything works fine until I request a thumbnail of 256x256, atwhich point only half of the data seems to be recieved. I'mdoing all of this over loopback for testing.
For instance, the client reports that it is sending 8000 bytes,and the server says it only receives 4000ish.
I've spend countless hours scouring google, but have come up withnothing. The curious thing is that when I set breakpoints on thereceiving loop (See below), all the data is received.
//Read the bytes from the network stream in to the memory stream
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = BUFFER_SIZE;
long totalBytes = 0;
do
{
bytesRead = networkStream.Read(buffer, 0, BUFFER_SIZE);
totalBytes += bytesRead;
ms.Write(buffer, 0, bytesRead);
}
while(networkStream.DataAvailable);
I then just do:
Image thumb = Image.FromStream(ms);
pictureBox1.Image = thumb;
I've tried every combination of Sockets, NetworkStreams,StreamWriters/Readers, but nothing seems to work. It would makemy week if anyone could shed light on this behaviour.
All the best,
Neil Saunders.
I've recently started to teach myself C#, and to begin with Ihave aimed to write a simple client/server system whereby theserver can request a thumbnail of the clients screen to betransmitted back. After brushing up on my windows GDI knowledge,the system quite happily snaps the screen, usesImage.GetThumbnail to shrink it, and then saves this to aMemoryStream, which is then transmitted back to the Server.Everything works fine until I request a thumbnail of 256x256, atwhich point only half of the data seems to be recieved. I'mdoing all of this over loopback for testing.
For instance, the client reports that it is sending 8000 bytes,and the server says it only receives 4000ish.
I've spend countless hours scouring google, but have come up withnothing. The curious thing is that when I set breakpoints on thereceiving loop (See below), all the data is received.
//Read the bytes from the network stream in to the memory stream
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = BUFFER_SIZE;
long totalBytes = 0;
do
{
bytesRead = networkStream.Read(buffer, 0, BUFFER_SIZE);
totalBytes += bytesRead;
ms.Write(buffer, 0, bytesRead);
}
while(networkStream.DataAvailable);
I then just do:
Image thumb = Image.FromStream(ms);
pictureBox1.Image = thumb;
I've tried every combination of Sockets, NetworkStreams,StreamWriters/Readers, but nothing seems to work. It would makemy week if anyone could shed light on this behaviour.
All the best,
Neil Saunders.