I am following a tutorial about Datagram Networkings on Java. I am creating the UDP Server, I copied the code on the website, but it says that it couldnt find getNextQuote() this function. I was wondering what is wrong here?
public void run(){
while(moreQuotes){
try{
byte[] buf = new byte[256];
DatagramPacket packet = new DatagramPacket(buf,buf.length);
socket.receive(packet);
InetAddress address = packet.getAddress();
int port = packet.getPort();
String dString = null;
if (in == null)
dString = new Date().toString();
else
dString = getNextQuote();
buf = dString.getBytes();
DatagramPacket newPacket = new DatagramPacket(buf,buf.length,address,port);
socket.send(newPacket);
} catch(IOException e) {
e.printStackTrace();
moreQuotes = false;
}
Maybe you should copy all functions of class from the tutorial? I past your code to google and find this link which contains whole implementation:
private String getNextQuote()
{
String returnValue = null;
try
{
if ((returnValue = qfs.readLine()) == null)
{
qfs.close();
this.openInputFile();
returnValue = qfs.readLine();
}
}
catch (IOException e)
{
returnValue = "IOException occurred in server.";
}
return returnValue;
}