public void onClick(View v) { if (v == btnConnect) { try { networkConnection = new NetworkConnection( progressBar, getString(R.string.simplehttpurl), this, connectIntent, INTENT_NEXT_SCREEN); networkConnection.start(); btnConnect.setVisibility(Button.INVISIBLE); btnCancel.setVisibility(Button.VISIBLE); } catch (Exception ex) { Log.e(getClass().getName(), "Error on onClick btnConnect ", ex); } } else if (v == btnCancel) { if (networkConnection != null) { try { networkConnection.close(); } catch (Exception ex) { Log.e(getClass().getName(), "Error on onClick btnCancel ", ex); } } reset(); } }
void connect(Socket s) throws IOException { Long host = getHostIdentifier(s.getInetAddress(), s.getPort()); if (myConnections.containsKey(host)) { throw new IOException("Already connected to host: " + host); } NetworkConnection conn = new NetworkConnection(this, host, s, myListener.queue); myConnections.put(host, conn); conn.start(); }