P
Pedro Sousa
Hi,
I'm using a TCP connection for sending text commands and receive text
answers from a server using a proprietary protocol. In one of the
responses the server sends binary data from an image file.
I'm using StreamReader.ReadLine() method for the general message
receiving, but when the binary data comes, it should be read with
BinaryReader.Read(...) method.
I'm only creating the BinaryReader from the underlying NetworkStream
whenever I know that the binary data is arriving. The binary data is
preceeded by the string "data=", which I also try to read using the
BinaryReader's Read(...) method, and the size of the image data
(number of bytes) has been sent earlier by the server.
When running on the full desktop framework, I can successfully read
the sentence "data=" from the stream using the BinaryReader (converted
from bytes to string using the ASCII encoding). However, when running
under the Compact Framework (either in the Emulator or in the device
itself) I always read 5 "garbage bytes" instead of "data="...
What am I doing wrong? Is there some kind of problem in the alternate
use of StreamReader and BinaryReader on the same underlying
NetworkStream? Should the BinaryReader be instantiated earlier?
Thanks in advance,
I'm using a TCP connection for sending text commands and receive text
answers from a server using a proprietary protocol. In one of the
responses the server sends binary data from an image file.
I'm using StreamReader.ReadLine() method for the general message
receiving, but when the binary data comes, it should be read with
BinaryReader.Read(...) method.
I'm only creating the BinaryReader from the underlying NetworkStream
whenever I know that the binary data is arriving. The binary data is
preceeded by the string "data=", which I also try to read using the
BinaryReader's Read(...) method, and the size of the image data
(number of bytes) has been sent earlier by the server.
When running on the full desktop framework, I can successfully read
the sentence "data=" from the stream using the BinaryReader (converted
from bytes to string using the ASCII encoding). However, when running
under the Compact Framework (either in the Emulator or in the device
itself) I always read 5 "garbage bytes" instead of "data="...
What am I doing wrong? Is there some kind of problem in the alternate
use of StreamReader and BinaryReader on the same underlying
NetworkStream? Should the BinaryReader be instantiated earlier?
Thanks in advance,