// TODO Review why addressIsServicedByReceiver is in the
 // StandardConnectionHandler class?!
 protected boolean addressIsServicedByReceiver(String address) {
   if (isConnected) {
     return handler.addressIsServicedByReceiver(address);
   } else {
     return false;
   }
 }
 protected boolean isBound() {
   // we only have a ProtocolHandler if this StandardConnectionHandler is
   // connected
   if (isConnected) {
     return handler.getSession().isBound();
   } else {
     return false;
   }
 }
  private void runThread() {

    do // process connections forever
    {
      do // {accept connection, create protocol handler, {read PDU,handle
      // it}, close connection}
      {
        try {
          logger.info("StandardConnectionHandler waiting for connection");
          socket = ss.accept();
          logger.info("StandardConnectionHandler accepted a connection");
          isConnected = true;
          is = socket.getInputStream();
          os = socket.getOutputStream();
          Class c = Class.forName(SMPPSim.getProtocolHandlerClassName());
          handler = (StandardProtocolHandler) c.newInstance();
          handler.setConnection(this);
          logger.info("Protocol handler is of type " + handler.getName());
        } catch (Exception exception) {
          logger.warning("Exception processing connection: " + exception.getMessage());
          logger.warning("Exception is of type: " + exception.getClass().getName());
          exception.printStackTrace();
          try {
            socket.close();
          } catch (Exception e) {
            logger.warning("Could not close socket following exception");
            e.printStackTrace();
          }
        }
      } while (!isConnected);

      do // until UNBIND or state violation
      {
        try {
          logger.finest("at start of main loop");
          readPacketInto(is);
          smsc.writeBinarySme(message);
          if (SMPPSim.isCallback() && smsc.isCallback_server_online()) {
            smsc.sent(response);
          }
          logger.finest("read packet");
          handler.processMessage(message);
        } catch (SocketException se) {
          logger.info("Socket exception: probably connection closed by client without UNBIND");
          se.printStackTrace();
          handler.getSession().setBound(false);
          if (handler.getSession().isReceiver()) smsc.receiverUnbound();
          isConnected = false;
        } catch (Exception exception) {
          logger.info(exception.getMessage());
          exception.printStackTrace();
          try {
            socket.close();
          } catch (Exception e) {
            logger.warning("Could not close socket following exception");
            e.printStackTrace();
          }
          handler.getSession().setBound(false);
          isConnected = false;
        }
      } while (isConnected);
      logger.finest("leaving connection handler main loop");
    } while (true);
  }
 protected boolean isReceiver() {
   return handler.getSession().isReceiver();
 }