private byte[] doUdpQuery(Packet pkt,InetAddress server,int port,int retry,int xid) throws IOException, NamingException {
  int minTimeout=50;
synchronized (udpSocket) {
    DatagramPacket opkt=new DatagramPacket(pkt.getData(),pkt.length(),server,port);
    DatagramPacket ipkt=new DatagramPacket(new byte[8000],8000);
    udpSocket.connect(server,port);
    int pktTimeout=(timeout * (1 << retry));
    try {
      udpSocket.send(opkt);
      int timeoutLeft=pktTimeout;
      int cnt=0;
      do {
        if (debug) {
          cnt++;
          dprint("Trying RECEIVE(" + cnt + ") retry("+ (retry + 1)+ ") for:"+ xid+ "    sock-timeout:"+ timeoutLeft+ " ms.");
        }
        udpSocket.setSoTimeout(timeoutLeft);
        long start=System.currentTimeMillis();
        udpSocket.receive(ipkt);
        long end=System.currentTimeMillis();
        byte[] data=new byte[ipkt.getLength()];
        data=ipkt.getData();
        if (isMatchResponse(data,xid)) {
          return data;
        }
        timeoutLeft=pktTimeout - ((int)(end - start));
      }
 while (timeoutLeft > minTimeout);
    }
  finally {
      udpSocket.disconnect();
    }
    return null;
  }
}

private byte [ ] doUdpQuery ( Packet pkt , InetAddress server , int port , int retry , int xid ) throws IOException , NamingException { int minTimeout = 50 ; synchronized ( udpSocket ) { DatagramPacket opkt = new DatagramPacket ( pkt . getData ( ) , pkt . length ( ) , server , port ) ; DatagramPacket ipkt = new DatagramPacket ( new byte [ 8000 ] , 8000 ) ; udpSocket . connect ( server , port ) ; int pktTimeout = ( timeout * ( 1 << retry ) ) ; try { udpSocket . send ( opkt ) ; int timeoutLeft = pktTimeout ; int cnt = 0 ; do { if ( debug ) { cnt ++ ; dprint ( "Trying RECEIVE(" + cnt + ") retry(" + ( retry + 1 ) + ") for:" + xid + "    sock-timeout:" + timeoutLeft + " ms." ) ; } udpSocket . setSoTimeout ( timeoutLeft ) ; long start = System . currentTimeMillis ( ) ; udpSocket . receive ( ipkt ) ; long end = System . currentTimeMillis ( ) ; byte [ ] data = new byte [ ipkt . getLength ( ) ] ; data = ipkt . getData ( ) ; if ( isMatchResponse ( data , xid ) ) { return data ; } timeoutLeft = pktTimeout - ( ( int ) ( end - start ) ) ; } while ( timeoutLeft > minTimeout ) ; } finally { udpSocket . disconnect ( ) ; } return null ; } }
tries to retreive an udp packet matching the given xid received within the timeout . if a packet with different xid is received , the received packet is enqueued with the corresponding xid in ' resps ' .
