public void run() {
   try {
     while (!iFinish) {
       Object command = null;
       try {
         command = RemoteIo.readObject(iSocket);
       } catch (java.io.EOFException ex) {
       }
       ;
       if (command == null) continue;
       Object ret = null;
       try {
         ret = answer(command);
       } catch (Exception e) {
         ret = e;
       }
       RemoteIo.writeObject(iSocket, ret);
     }
   } catch (Exception e) {
     sLog.error(e.getMessage(), e);
   }
   unregister();
   try {
     iSocket.close();
   } catch (Exception e) {
   }
 }
 public void run() {
   iStartTime = new Date();
   try {
     ConnectionFactory.init(
         ApplicationProperties.getProperties(), ApplicationProperties.getDataFolder());
     try {
       while (true) {
         try {
           iServerSocket =
               ConnectionFactory.getServerSocketFactory()
                   .createServerSocket(
                       Integer.parseInt(
                           ApplicationProperties.getProperty(
                               "tmtbl.solver.register.port", "9998")));
           sLog.info(
               "Service is running at "
                   + iServerSocket.getInetAddress().getHostName()
                   + ":"
                   + iServerSocket.getLocalPort());
           break;
         } catch (BindException e) {
           try {
             sLog.warn("Prior instance of service still running");
             Socket socket =
                 ConnectionFactory.getSocketFactory()
                     .createSocket(
                         "localhost",
                         Integer.parseInt(
                             ApplicationProperties.getProperty(
                                 "tmtbl.solver.register.port", "9998")));
             RemoteIo.writeObject(socket, "quit");
             Object answer = RemoteIo.readObject(socket);
             sLog.warn("quit command sent, answer: " + answer);
             socket.close();
           } catch (Exception f) {
             sLog.warn("Unable to connect to prior instance", f);
           }
           sleep(1000);
         }
       }
     } catch (IOException io) {
       sLog.error("Unable to start service, reason: " + io.getMessage(), io);
       return;
     }
     while (!iServerSocket.isClosed()) {
       try {
         Socket socket = iServerSocket.accept();
         socket.setKeepAlive(true);
         sLog.debug("Client " + socket.getInetAddress() + " connected.");
         (new Thread(new SolverConnection(socket))).start();
       } catch (Exception e) {
         if (!iServerSocket.isClosed())
           sLog.warn("Unable to accept new connection, reason:" + e.getMessage(), e);
       }
     }
   } catch (Exception e) {
     sLog.error("Unexpected exception occured, reason: " + e.getMessage(), e);
   } finally {
     try {
       if (iServerSocket != null && !iServerSocket.isClosed()) iServerSocket.close();
     } catch (Exception e) {
       sLog.warn("Unable to close socket, reason: " + e.getMessage(), e);
     }
   }
 }