public static void SendMessage(RobotProperties properties)
{
string output = JsonConvert.SerializeObject(properties);
// Translate the passed message into ASCII and store it as a Byte array.
Byte[] data = Encoding.UTF8.GetBytes(output);
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
Console.WriteLine("Sent:\n {0}", data);
// Receive the TcpServer.response.
// Buffer to store the response bytes.
data = new Byte[1000];
// Read the TcpServer response bytes into data buffer. stream.Read returns the number of bytes read which are stored into the bytes variable.
Int32 bytes = stream.Read(data, 0, data.Length);
string dataReceived = Encoding.Default.GetString(data);
Console.WriteLine("This was received: {0}", dataReceived);
if (dataReceived.Equals("Received") && count<50)
{
Console.WriteLine("Check if it gets here");
properties.x -= 1;
count++;
SendMessage(properties);
}
}
计数被初始化为0。尽管客户端确实接收到数据,即“已接收”并且计数低于50,但它不会进入if语句中并进行递归调用。可能出什么问题了?