Hi,
the problem is quite simple yet I can’t find a solution. I have a string value “sam” that I send through named pipes to my unity application. I receive the string and can print it in the log without issues, but if I use that string to compare with another string of same value created in unity itself (using IF or SWITCH functions), unity finds they don’t match.
My code, server side (Winform app):
dataWriter("sam");
void dataWriter(string dataToSend)
{
byte[] _buffer = Encoding.UTF8.GetBytes(dataToSend);
pipeServer.BeginWrite(_buffer, 0, _buffer.Length, new AsyncCallback(asyncWriter), pipeServer);
}
private void asyncWriter(IAsyncResult result)
{
pipeServer = (NamedPipeServerStream)result.AsyncState;
pipeServer.EndWrite(result);
pipeServer.WaitForPipeDrain();
pipeServer.Flush();
}
On the client side (unity app) :
if (pipeStream.IsConnected)
{
Debug.Log("Start Reading");
pipeStream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(readCallBack), pipeStream);
}
private void readCallBack(IAsyncResult result)
{
pipeStream.EndRead(result);
string stringData = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
Debug.Log("Data received : " + stringData); /// Will successfully print "Data received : sam" in unity logs
if (stringData == "sam") //// Will be FALSE
{
Debug.Log("Data received = sam");
}
else
{
Debug.Log("Data received does not equal SAM "); // Will print this, because it finds stringData is not equal to "sam"
}
}
I tried alot of things: change the encoding format, tried to transform the IF variable from string to byte to string using UTF8 encoding in hopes of having the same string as the data received, tried to trim the BOM from the string if there was any but apparently there is none already, etc.
Please save me from hell on earth!!