public class PortListener extends HttpServlet {
private Socket sock;
private ServerSocket serverSocket;
private Timer timer;
private int a = 0;
public void init() throws ServletException
{
try{
timer = new Timer();
timer.schedule(new ToDoTask(), 5000);
}catch(Exception ex)
{
Logger.getLogger(PortListener.class.getName()).log(Level.SEVERE, null, ex) ;
}
}
class ToDoTask extends TimerTask
{
public void run()
{
try
{
timer.cancel();
InputStream is = getServletContext().getResourceAsStream("/WEB-INF/navl.properties");
Properties p = new Properties();
p.load(is);
is.close();
String pro = p.getProperty("dataPort");
int port = Integer.parseInt(pro);
serverSocket = new ServerSocket(port);
while (true)
{
System.out.println("Listening on ...... " + port);
sock = serverSocket.accept();
Thread t = new Thread(new ModuleHandler(sock));
t.start();
//startthread(sock);
}
}catch(Exception ex)
{
System.out.println("Exception in PortListener");
Logger.getLogger(PortListener.class.getName()).log(Level.SEVERE, null, ex) ;
}
}
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
|