我正在尝试构建一个简单的UDP服务器,在其中接收字符串,在字符串上添加“:” +整数值,然后将其发送回去:
while(true)
{
buffer = new byte[10000];
DatagramPacket request= new DatagramPacket(buffer,buffer.length);
asocket.receive(request);
byte[] data=request.getData();
String stringData= new String(data);
System.out.println(stringData);
System.out.println(seqNumber);
stringData+=":" + seqNumber;
System.out.println(stringData);
DatagramPacket output = new DatagramPacket(stringData.getBytes(),stringData.getBytes().length,group,9005);
broadcastSocket.send(output);
seqNumber++;
}
问题是当打印出变量stringData时,它永远不会连接:+整数值。这里我缺少什么吗?