/** Handle incoming response here */ public void notifyResponse(SipClientConnection scc) { int statusCode = 0; boolean received = false; try { scc.receive(0); // <i><b>fetch resent response</b></i> statusCode = scc.getStatusCode(); str = new StringItem("Response: ", statusCode + " " + scc.getReasonPhrase()); form.append(str); if (statusCode < 200) { dialog = scc.getDialog(); form.append("Early-Dialog state: " + dialog.getState()); } if (statusCode == 200) { String contentType = scc.getHeader("Content-Type"); String contentLength = scc.getHeader("Content-Length"); int length = Integer.parseInt(contentLength); if (contentType.equals("application/sdp")) { // // <i><b>handle SDP here</b></i> // } dialog = scc.getDialog(); // <i><b>save dialog info</b></i> form.append("Dialog state: " + dialog.getState()); scc.initAck(); // <i><b>initialize and send ACK</b></i> scc.send(); str = new StringItem("Session established: ", scc.getHeader("Call-ID")); form.append(str); scc.close(); } else if (statusCode >= 300) { str = new StringItem("Session failed: ", scc.getHeader("Call-ID")); form.append(str); form.removeCommand(byeCmd); form.addCommand(restartCmd); scc.close(); } } catch (IOException ioe) { // <i><b>handle e.g. transaction timeout here</b></i> str = new StringItem("No answer: ", ioe.getMessage()); form.append(str); form.removeCommand(byeCmd); form.addCommand(restartCmd); } }
/** end session with BYE */ private void sendBYE() { if (dialog != null) { try { SipClientConnection sc = dialog.getNewClientConnection("BYE"); sc.send(); str = new StringItem("user hang-up: ", "BYE sent..."); form.append(str); boolean gotit = sc.receive(10000); if (gotit) { if (sc.getStatusCode() == 200) { form.append("Session closed successfully..."); form.append("Dialog state: " + dialog.getState()); } else form.append("Error: " + sc.getReasonPhrase()); } sc.close(); } catch (IOException iox) { form.append("Exception: " + iox.getMessage()); } } else { form.append("No dialog information!"); } }