cossy74
asked on
TcpClient and Sending Integers, Doubles, etc
Hi,
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( BitConvert er.GetByte s(SendingO ne)); // 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
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
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
int SendingOne = Convert.ToInt16(data); // This doesn't work
Client Side:
Byte[] byteData = System.Text.Encoding.Defau lt.GetByte s(SendingO ne);
then write the data in to port.
Byte[] byteData = System.Text.Encoding.Defau
then write the data in to port.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Client:
Modify
Byte[] data = BitConverter.GetBytes(Send
Server:
Remove data = System.Text....
Modify
int SendingOne = BitConverter.ToInt32(i,0);