private void startListener() { try { if (scn != null) scn.close(); // <i><b>listen to requests on port 5060</b></i> scn = (SipConnectionNotifier) Connector.open("sip:5080"); scn.setListener(this); } catch (IOException ex) { // <i><b>handle IOException</b></i> } }
private void stopListener() { try { if (scn != null) scn.close(); scn = null; } catch (IOException ex) { // <i><b>handle IOException</b></i> } }
public void notifyRequest(SipConnectionNotifier sn) { try { ssc = scn.acceptAndOpen(); // <i><b>blocking</b></i> if (ssc.getMethod().equals("BYE")) { // <i><b>respond 200 OK to BYE</b></i> ssc.initResponse(200); ssc.send(); str = new StringItem("Other side hang-up!", ""); form.append(str); } form.append("Closing notifier..."); form.removeCommand(byeCmd); form.addCommand(restartCmd); scn.close(); } catch (IOException ex) { // <i><b>handle IOException</b></i> } }
/** * Sets appropriate CSeq and Via headers in the given request preparing it for sending. * * @param clonedRequest the request to modify */ public synchronized void setRequestHeaders(Request clonedRequest) { // RFC 3261, section 10.2.4, Refreshing Bindings: // "A UA SHOULD use the same Call-ID for all registrations during a // single boot cycle". // // Call-Id header was added in SipClientConnectionImpl.send() // when the initial request was sent. This is the reason why // Call-Id header is not added here. // Update the CSeq header. RFC 3261, p. 58: // A UA MUST increment the CSeq value by one for each // REGISTER request with the same Call-ID. CSeqHeader cseq = clonedRequest.getCSeqHeader(); if (cseq != null) { cseq.setSequenceNumber(cseq.getSequenceNumber() + 1); } else { // log an error if (Logging.REPORT_LEVEL <= Logging.ERROR) { Logging.report( Logging.ERROR, LogChannels.LC_JSR180, "RefreshTask.run(): The request doesn't " + "contain CSeq header!"); } } // ViaHeader clonedRequest.removeHeader(ViaHeader.NAME); Vector viaHeaders = new Vector(); try { ViaHeader viaHeader = StackConnector.headerFactory.createViaHeader( sipConnectionNotifier.getLocalAddress(), sipConnectionNotifier.getLocalPort(), ((SipConnectionNotifierImpl) sipConnectionNotifier) .getSipProvider() .getListeningPoint() .getTransport(), null); viaHeaders.addElement(viaHeader); } catch (ParseException ex) { if (Logging.REPORT_LEVEL <= Logging.WARNING) { Logging.report( Logging.WARNING, LogChannels.LC_JSR180, "RefreshTask.run(): can't create Via header: " + ex); } } catch (IOException ioe) { if (Logging.REPORT_LEVEL <= Logging.WARNING) { Logging.report( Logging.WARNING, LogChannels.LC_JSR180, "RefreshTask.run(): can't create Via header: " + ioe); } } try { clonedRequest.setVia(viaHeaders); } catch (SipException ex) { if (Logging.REPORT_LEVEL <= Logging.WARNING) { Logging.report( Logging.WARNING, LogChannels.LC_JSR180, "RefreshTask.run(): can't set Via header: " + ex); } } }