if (socket == null)
return;
while (moreQuotes) {
try {
byte[] buf = new byte[256];
DatagramPacket packet;
InetAddress address;
int port;
String dString = null;
// receive request
packet = new DatagramPacket(buf, 256);
socket.receive(packet);
address = packet.getAddress();
port = packet.getPort();
// send response
if (qfs == null)
dString = new Date().toString();
else
dString = getNextQuote();
dString.getBytes(0, dString.length(), buf, 0);
packet = new DatagramPacket(buf, buf.length, address, port);
socket.send(packet);
} catch (IOException e) {
System.err.println("IOException: " + e);
moreQuotes = false;
e.printStackTrace();
}
}
socket.close();