{
String ip = "";
int port = 0;
BrowseSocket bs = null;
MessageStream ms = new MessageStream(server);
MessageHandler.subscribe(DirectBrowseAckMessage.TYPE, ms);
MessageHandler.subscribe(DirectBrowseErrorMessage.TYPE, ms);
server.send(new DirectBrowseRequestMessage(getUser().getName()));
// wait for ack
IOException e = null;
long startTime = System.currentTimeMillis();
while (true) {
long timeLeft = SERVER_TIMEOUT - (System.currentTimeMillis()
- startTime);
if (timeLeft <= 0) {
e = new IOException("server timeout");
break;
}
if (ms.hasNext(100)) {
ServerMessage msg = ms.next();
if (msg instanceof DirectBrowseErrorMessage) {
DirectBrowseErrorMessage m = (DirectBrowseErrorMessage)msg;
if (m.nick.equals(getUser().getName())) {
e = new IOException(m.message);