DatagramSocket ds = new DatagramSocket(this.my_listening_port);
byte[] rcv_data = new byte[1024];
DatagramPacket dp = new DatagramPacket(rcv_data,rcv_data.length);
String rcv_data_string[] = new String[no_of_child_node];
for(int i=0; i<no_of_child_node; i++)
{
ds.receive(dp);
rcv_data_string[i] = new String(dp.getData());
System.out.println("result of child " + i + ": " + rcv_data_string[i]);
}
String query_result = new String();
query_result += this.self_node_id;
for(int i=0; i<no_of_child_node ; i++)
{
System.out.println("result of child " + i + ": " + rcv_data_string[i]);
query_result = query_result.concat(rcv_data_string[i]);
}
ds.close();
System.out.println("Final result of me and child : " + query_result);
sending_result_to_parent(query_result);
输出:
result of child 0: t2
result of child 1: t5
result of child 2: t3t1
result of child 0: t2
result of child 1: t5
result of child 2: t3t1
Final result of me and child : t4t2
我预期的最终结果: 我和孩子的最终结果:t4t2t5t3t1
上述代码有什么问题? 所以,有人可以告诉可能是什么问题吗?