The problem is that it ALWAYS throws an EOF Exception, as the client
is trying to read in the data before the server has a chance to send
it (the client recovers quicker after the initial handshake than the
server who has to find the data within a database, construct a packet
and send it out to the client.) I want the client to wait until a
certain amount of data is available before continuing (or timeout if
the data doesn't present itself within 30 seconds).
Surely this is a common problem when writing client/server
applications? Has anyone else had any experience with this problem?
As an aside, in a previous program (that used threads) I used the
code:
while(in.available() < 5)
{
try
{
sleep(10);
}
catch(InterruptedException e)
{
}
}
...which worked fine. However my current program does not use
threads, and I would have difficulty changing it to do so.
Plus the main method would then end up just calling:
thread.start();
thread.join();
which seems a bit wasteful. There must be a more elegant solution?