public void run() {
int recvierCount = 0;
System.out.println("ReciveMessageThread is run.");
byte[] buf = new byte[4096];
try {
file = new File(filePath);
if (!file.exists()) {
file.createNewFile();
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
} else {
fos = new FileOutputStream(file, true);
bos = new BufferedOutputStream(fos);
}
while (jms != null) {
recvierCount++;
DatagramPacket dp = new DatagramPacket(buf, buf.length);
System.out.println(dp.getData());
try {
jms.receive(dp);
} catch (SocketTimeoutException e) {
System.out.println("not data.");
break;
} finally {
bos.write(dp.getData());
}
}
文章来源于领测软件测试网 https://www.ltesting.net/