public boolean waitForDisconnect(long timeout) {
    initErrorInfo();

    RequestEvent event = parent.waitRequest(timeout);

    if (event == null) {
      setReturnCode(parent.getReturnCode());
      setErrorMessage(parent.getErrorMessage());
      setException(parent.getException());

      return false;
    }

    Request request = event.getRequest();
    receivedRequests.add(new SipRequest(event));

    while (request.getMethod().equals(Request.BYE) == false) {
      event = parent.waitRequest(timeout); // TODO, adjust

      if (event == null) {
        setReturnCode(parent.getReturnCode());
        setErrorMessage(parent.getErrorMessage());
        setException(parent.getException());

        return false;
      }

      request = event.getRequest();
      receivedRequests.add(new SipRequest(event));
      continue;
    }

    ServerTransaction tr = event.getServerTransaction();

    if (tr == null) {
      try {
        tr = parent.getParent().getSipProvider().getNewServerTransaction(request);
      } catch (Exception ex) {
        setReturnCode(SipSession.EXCEPTION_ENCOUNTERED);
        setErrorMessage("Exception: " + ex.getClass().getName() + ": " + ex.getMessage());
        setException(ex);

        return false;
      }
    }

    dialog = tr.getDialog();

    transaction = new SipTransaction();
    transaction.setServerTransaction(tr);

    return true;
  }
public boolean waitForDisconnect ( long timeout ) { initErrorInfo ( ) ; RequestEvent event = parent . waitRequest ( timeout ) ; if ( event == null ) { setReturnCode ( parent . getReturnCode ( ) ) ; setErrorMessage ( parent . getErrorMessage ( ) ) ; setException ( parent . getException ( ) ) ; return false ; } Request request = event . getRequest ( ) ; receivedRequests . add ( new SipRequest ( event ) ) ; while ( request . getMethod ( ) . equals ( Request . BYE ) == false ) { event = parent . waitRequest ( timeout ) ; if ( event == null ) { setReturnCode ( parent . getReturnCode ( ) ) ; setErrorMessage ( parent . getErrorMessage ( ) ) ; setException ( parent . getException ( ) ) ; return false ; } request = event . getRequest ( ) ; receivedRequests . add ( new SipRequest ( event ) ) ; continue ; } ServerTransaction tr = event . getServerTransaction ( ) ; if ( tr == null ) { try { tr = parent . getParent ( ) . getSipProvider ( ) . getNewServerTransaction ( request ) ; } catch ( Exception ex ) { setReturnCode ( SipSession . EXCEPTION_ENCOUNTERED ) ; setErrorMessage ( "Exception: " + ex . getClass ( ) . getName ( ) + ": " + ex . getMessage ( ) ) ; setException ( ex ) ; return false ; } } dialog = tr . getDialog ( ) ; transaction = new SipTransaction ( ) ; transaction . setServerTransaction ( tr ) ; return true ; }
The waitForDisconnect() method waits for a BYE request addressed to this user agent to be
received from the network. Call this method after calling the listenForDisconnect() method.

<p>
This method blocks until one of the following occurs: 1) A BYE request message has been
received, addressed to this user agent. In this case, a value of true is returned. The
getLastReceivedRequest() method can be called to get information about the received BYE
request. Use the method respondToDisconnect() for responding to the received BYE request. 2)
The wait timeout period specified by the parameter to this method expires. false is returned in
this case. 3) An error occurs. false is returned in this case.

<p>
Any non-BYE requests received for this user agent are collected while waiting for a BYE message
and can be seen by calling getAllReceivedRequests() once this method returns.

<p>
Regardless of the outcome, incoming requests associated with this User Agent will continue to
be queued up until the stopListeningForRequests() method is called. IT IS RECOMMENDED THAT THE
CALLING PROGRAM STOP LISTENING FOR REQUESTS WHILE NONE ARE EXPECTED. Otherwise alot of overhead
is used up and wasted. Once a listenForXXX() method has been called (pre-requisite to calling
this method) and until the stopListeningForRequests() method is called, the calling program can
continue to retrieve specific subsequently received requests by calling one of the waitForXxx()
methods.

@param timeout The maximum amount of time to wait, in milliseconds. Use a value of 0 to wait
indefinitely.
@return false in the case of wait timeout or error; call getReturnCode() and/or
getErrorMessage() and, if applicable, getException() for further diagnostics. A true
value is returned if a BYE message was received. Call the getLastReceivedRequest()
method to get information about the BYE, and call the respondToDisconnect() method to
send a response to the BYE.