Kinda long title, but anyways...
I\'ve been looking at these examples, specifically on the parts on writing and reading the size of the message to the byte streams
I guess this should do that: (I assume your data is a string)
Stream stream = tcpClient.GetStream(); Encoding encoding = Encoding.GetEncoding("encoding name"); byte[] bytes = encoding.getBytes(data); stream.Write(BitConverter.GetBytes((short)bytes.Length),0,2); // hope data isn't longer that 64k stream.Write(bytes,0,bytes.Length);