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 startSession() { SipClientConnection scc = null; try { // <i><b>start a listener for incoming requests</b></i> startListener(); // <i><b>open SIP connection with remote user</b></i> scc = (SipClientConnection) Connector.open(address.getString()); scc.setListener(this); // <i><b>initialize INVITE request</b></i> scc.initRequest("INVITE", scn); scc.setHeader("Content-Length", "" + sdp.length()); scc.setHeader("Content-Type", "application/sdp"); OutputStream os = scc.openContentOutputStream(); os.write(sdp.getBytes()); os.close(); // <i><b>close and send</b></i> str = new StringItem("Inviting... ", scc.getHeader("To")); form.append(str); } catch (Exception ex) { ex.printStackTrace(); // <i><b>handle IOException</b></i> } }
/** * Get the list of suites for the user to install. The suites that are listed are the links on a * web page that end with .jad. */ public void run() { StreamConnection conn = null; InputStreamReader in = null; String errorMessage; long startTime; startTime = System.currentTimeMillis(); try { parent.displayProgressForm( Resource.getString(ResourceConstants.AMS_DISC_APP_GET_INSTALL_LIST), "", url, 0, Resource.getString(ResourceConstants.AMS_GRA_INTLR_CONN_GAUGE_LABEL)); conn = (StreamConnection) Connector.open(url, Connector.READ); in = new InputStreamReader(conn.openInputStream()); try { parent.updateProgressForm( "", 0, Resource.getString(ResourceConstants.AMS_DISC_APP_GAUGE_LABEL_DOWNLOAD)); parent.installList = SuiteDownloadInfo.getDownloadInfoFromPage(in); if (parent.installList.size() > 0) { parent.installListBox = new List( Resource.getString(ResourceConstants.AMS_DISC_APP_SELECT_INSTALL), Choice.IMPLICIT); // Add each suite for (int i = 0; i < parent.installList.size(); i++) { SuiteDownloadInfo suite = (SuiteDownloadInfo) installList.elementAt(i); parent.installListBox.append(suite.label, (Image) null); } parent.installListBox.addCommand(parent.backCmd); parent.installListBox.addCommand(parent.installCmd); parent.installListBox.setCommandListener(parent); /* * We need to prevent "flashing" on fast development * platforms. */ while (System.currentTimeMillis() - parent.lastDisplayChange < GraphicalInstaller.ALERT_TIMEOUT) ; parent.display.setCurrent(parent.installListBox); return; } errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_CHECK_URL_MSG); } catch (IllegalArgumentException ex) { errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_URL_FORMAT_MSG); } catch (Exception ex) { errorMessage = ex.getMessage(); } } catch (Exception ex) { errorMessage = Resource.getString(ResourceConstants.AMS_DISC_APP_CONN_FAILED_MSG); } finally { if (parent.progressForm != null) { // end the background thread of progress gauge. Gauge progressGauge = (Gauge) parent.progressForm.get(parent.progressGaugeIndex); progressGauge.setValue(Gauge.CONTINUOUS_IDLE); } try { conn.close(); in.close(); } catch (Exception e) { if (Logging.REPORT_LEVEL <= Logging.WARNING) { Logging.report(Logging.WARNING, LogChannels.LC_AMS, "close threw an Exception"); } } } Alert a = new Alert( Resource.getString(ResourceConstants.ERROR), errorMessage, null, AlertType.ERROR); a.setTimeout(Alert.FOREVER); parent.display.setCurrent(a, parent.urlTextBox); }