Ejemplo n.º 1
0
 public void run() {
   boolean status;
   sf.DEBUG("Listen server running.");
   // open up our server socket
   try {
     m_serverSocket = new ServerSocket(m_nPort);
   } catch (IOException e) {
     sf.VERBOSE("Could not listen on port: " + m_nPort);
     if (sf.cntrlWndw != null) {
       sf.cntrlWndw.ClearListenServer();
     }
     return;
   }
   sf.VERBOSE("Listening for client connections on port " + m_nPort);
   // if (SerialForward.bSourceSim)
   // {
   SetDataSource();
   sf.InitSerialPortIO();
   // }
   // start listening for connections
   try {
     ClientServicer rcv;
     Socket currentSocket;
     while (!m_bShutdown) {
       currentSocket = m_serverSocket.accept();
       ClientServicer newServicer = new ClientServicer(currentSocket, sf, this);
       newServicer.start();
       vctServicers.add(newServicer);
     }
     m_serverSocket.close();
   } catch (IOException e) {
     /*try { this.sleep(500); }
     catch (Exception e2) { }*/
     sf.VERBOSE("Server Socket closed");
   } finally {
     ShutdownAllClientServicers();
     if (sf.serialPortIO != null) sf.serialPortIO.Shutdown();
     sf.VERBOSE("--------------------------");
     if (sf.cntrlWndw != null) {
       sf.cntrlWndw.ClearListenServer();
     }
   }
 }
Ejemplo n.º 2
0
  public void Shutdown() {
    if (!m_bShutdown) {
      m_bShutdown = true;

      try {
        sf.dataSource.CloseSource();
      } catch (Exception e) {
      }

      try {
        if (m_serverSocket != null) m_serverSocket.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
      this.interrupt();
    }
  }