TcpClient and Sending Integers, Doubles, etc
Posted on 2006-11-01
I can find lots of things show how to send strings across a TcpClient using network streams. But my question is how do i send a number, in particluar an integer.
ON THE Client Side I have this....
int SendingOne = 1;
Byte data = System.Text.Encoding.ASCII.GetBytes(BitConverter.GetBytes(SendingOne)); // THis doesnot work.... what should it be????
stream.Write(data, 0, sizeof(int));
ON The Server Side I have this.....
i = stream.Read(bytes, 0, sizeof(int));
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
int SendingOne = Convert.ToInt16(data); // This doesn't work