long endTime;
synchronized (updateLock) {
tcpRegistered = false;
selector.wakeup();
endTime = System.currentTimeMillis() + timeout;
tcp.connect(selector, new InetSocketAddress(host, tcpPort), 5000);
}
// Wait for RegisterTCP.
synchronized (tcpRegistrationLock) {
while (!tcpRegistered && System.currentTimeMillis() < endTime) {
try {
tcpRegistrationLock.wait(100);
} catch (InterruptedException ignored) {
}
}
if (!tcpRegistered) {
throw new SocketTimeoutException("Connected, but timed out during TCP registration.\n"
+ "Note: Client#update must be called in a separate thread during connect.");
}
}
if (udpPort != -1) {
InetSocketAddress udpAddress = new InetSocketAddress(host, udpPort);
synchronized (updateLock) {
udpRegistered = false;
selector.wakeup();
udp.connect(selector, udpAddress);
}