Re: Truncated data using .NET 3.5 sockets VS 2008

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mon, 24 Mar 2008 08:55:19 -0700, Kenny D <kennydevries@xxxxxxxxxxx> wrote:

I am having trouble sending streams of data from one socket to another
using the following code.

When the transmitter is running on the same machine as the receiver,
the data transmits perfectly. When the transmitter runs on another
machine, the data gets truncated at semi random places.

You are using StreamReader.Peek() to decide whether you've reached the end of the stream. Except that, as I read the docs for StreamReader.Peek(), that's not what it's going to tell you. It will return -1 any time that there is no character _currently_ available. It doesn't tell you anything about whether a character _may_ become available in the future.

I recommend changing your code to read bytes, properly checking for the end of the stream by watching for a zero-byte read from the stream. When that happens, you will know that the connection has been closed, indicating the end of the stream, at which point you can decode the bytes you've received all at once.

I admit, I don't use StreamReader.Peek() and thus don't have first-hand experience with respect to what it really does. But the documentation certainly implies to me that you're using it wrong. And if that implication is correct, it would absolutely explain the behavior you're seeing.

Pete
.



Relevant Pages

  • Re: USB 2.0 Streaming through SMA
    ... data streaming from a PC using USB through the transmitter; ... and have the receiver stream to another PC. ... USB interface of the first PC and receive the data coming from the USB ...
    (comp.arch.embedded)
  • Re: Atmel AT91SAM7S Manchester encoder/decoder
    ... When I enable the manchester, I see my transmitted data getting coded ... using the timeout interrupt of the transmitter could be ... load a new character in the UART. ... I'm using the receiver timeout interrupt to signal received messages. ...
    (comp.arch.embedded)
  • Re: USB 2.0 Streaming through SMA
    ... data streaming from a PC using USB through the transmitter; ... and have the receiver stream to another PC. ... Anyhow, USB is the worst system for PC to PC communication, since USB ...
    (comp.arch.embedded)
  • Re: USB 2.0 Streaming through SMA
    ... data streaming from a PC using USB through the transmitter; ... and have the receiver stream to another PC. ... USB interface of the first PC and receive the data coming from the USB ...
    (comp.arch.embedded)
  • Re: Remote trigger device for D300s --- Uh-oh - how about this amusing little
    ... YongNuo camera wireless remote control shutter release YN-128 will use ... It's supports the multistage frequency trim combination, the transmitter ... and the receiver establishes separately has four digit switch codes, ... friendly, not only has the independent power supply switch, but also has ...
    (rec.photo.digital)