I am using a SwingWorker to read data over a TCP connection and display when it comes back.
new SwingWorker<EnvInfoProto, Void>() {
@Override
public EnvInfoProto doInBackground() {
try {
xxx.writeTo(socket.getOutputStream());
return ProtoMsg.parseFrom(socket.getInputStream());
} catch(IOException ignore) { }
return null;
}
@Override
public void done() {
try {
UpdateGui(get());
} catch (Exception ignore) {}
}
}.execute();
The problem arises when the socket is dead, e.g. after writeTo it waits eternally for input on the socket. What is the easiest way to timeout after a while? Is this also the best solution in this case? Would I still use a swingworker in that solution?
Thanks