my goal is to get a message from an other client over a server and work on with that message. Server and other client are in visual basic and if i try to communicate between two vb clients everything is fine, but i need the client in c# for my Unityproject. My Problem is that there are still empty Messages at the Console, so i think the if() doesn't work correct. Here is the relevant part of the Code:
try
{
theStream = mySocket.GetStream();
Byte[] inStream = new Byte[mySocket.SendBufferSize];
theStream.Read(inStream, 0, inStream.Length);
serverMsg += Encoding.ASCII.GetString(inStream);
serverMsg = serverMsg.Trim();
//if ((serverMsg == null || serverMsg == "")) doesn't work
//if (String.IsNullOrWhiteSpace(serverMsg)) doesn't work
//if (String.IsNullOrEmpty(serverMsg) || serverMsg.Length <1) doesn't work
INOWS = false;
INOWS = IsNullOrWhiteSpace(serverMsg);
if (INOWS)
{
// do nothing
}
else
{
Debug.Log("[SERVER] -> " + serverMsg);
}
}
catch (Exception e)
{
Debug.Log("[Fehler]" + e);
}
} while (socketReady == true);
public static bool IsNullOrWhiteSpace(string value)
{
if (value != null)
{
for (int i = 0; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i]))
{
return false;
}
}
}
return true;
}
Thanks to your hints i tried using IsNullOrWhiteSpace, but this gave me an error "'string' does not contain a definition for IsNullOrWhiteSpace"
So i used this IsNullOrWhitespace but i still get at least one empty string at the console for every korrekt string. console view Do you have any other hints for me?