How do I implement a web application with a Servlet that is listening on a port for socket connections?
See Question&Answers more detail:osHow do I implement a web application with a Servlet that is listening on a port for socket connections?
See Question&Answers more detail:osHaving the servlet open ServerSockets is a bad code smell. This is primarily because it is the container's responsibility to manage sockets (among other resources like worker threads, sessions etc).
That said, I do not think you need a servlet in the first place. Unless you want to access some of the container's services, it would be better if you use a J2SE application to manage ServerSockets.