So I'm writing two applications, one console application and one background/windows application. These two applications are made to communicate with eachother through TCP (I'm using TcpClient class and TcpListener class). The problem I have is that when I change the Output type of the background application from Console to Windows application the encoding gets kind of messed up and the output on the server (console server) prints some characters as gibberish.
I've tried setting different encodings for the socket streams but nothing seems to work.
TcpClient client = new TcpClient();
socketInput = new StreamWriter(client.GetStream());
socketOutput = new StreamReader(client.GetStream());
...
process.OutputDataReceived += new
DataReceivedEventHandler(p_OutputDataReceived);
...
static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data))
{
StringBuilder strOutput = new StringBuilder();
try
{
strOutput.Append(e.Data);
Console.WriteLine(strOutput);
socketInput.WriteLine(strOutput);
socketInput.Flush();
}
catch (Exception ex) { }
}
}