In C# I try to send a string through TcpClient as such:
byte[] outputOutStream = new byte[1024]; ASCIIEncoding outputAsciiEncoder string message //This is the message I want to send TcpClient outputClient = TcpClient(ip, port); Stream outputDataStreamWriter outputDataStreamWriter = outputClient.GetStream(); outputOutStream = outputAsciiEncoder.GetBytes(message); outputDataStreamWriter.Write(outputOutStream, 0, outputOutStream.Length);
I must to convert message from string to bytes, is there a way I can send it directly as string?
I know this is possible in Java.
Create a
StreamWriteron top of outputClient.GetStream:(You may want a
usingstatement to close the writer automatically, and you should also carefully consider which encoding you want to use. Are you sure you want to limit yourself to ASCII? If you control both sides of the connection so can pick an arbitrary encoding, then UTF-8 is usually a good bet.)