I initially used StreamReader/StreamWriter, but encountered problems with
unwanted character set conversions. I couldn't figure out how to use them to
send a stream of binary data that could not be altered by the receiver. Some
of the clients could be potentially using Chinese or other foreign
languages, and if I used stream.Write(buffer) on the sending side and then
read the data on the client side with stream.Read(buffer), certain
characters would be changed slightly. I am by no means an expert in Unicode
and the various conversions the .NET does automatically. I guess the
question I should ask is how can I set up a TCP stream that lets me tranfer
binary data without fear of implicit character conversion?
"Marcin Grzębski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:ct**********@nemesis.news.tpi.pl...
Hi Paul,
I'm not familiar with BinaryReader/Writer but if you're
saying that StreamReader/Writer is faster then you'll
need to think about using of that.
If you are writing (or reading) values one by one then
think about buffering them in the buffer (byte[]) and
write them in the pack.
HTH
Marcin
I am writing a client/server application that communicates over tcp. The
code I use to initiate the connection is as follows:
NetworkStream networkStream = new NetworkStream(ClientSocket);
toClient = new BinaryWriter(networkStream);
fromClient = new BinaryReader(networkStream);
There is similar code on the client side. This set up works fine and
communication does occur. However, the communication is very slow. This
is especially noticable if I transfer larger amounts of data such as a
file.
If I change the code around and use StreamReader/StreamWriter,
performance is significantly faster. I suspect it's some kind of
buffering issue. Any suggestions would be appreciated.