Servlet to implement socket connection

How to implement a web application with a servlet that listens on a port for socket connections?

+3
source share
3 answers

I assume that you do not mean the HTTP input connection that you get for free with the servlet container ... But if you want to add, say, the admin service, you can create a listener thread that sets some global state in the servlet. Please note that this is not considered kosher (and I believe that it might even violate the servlet standard).

+3
source

Having an openServerSockets servlet is a bad code smell. This is primarily due to the fact that the responsibility for managing sockets is the responsibility of the container (among other resources such as workflows, sessions, etc.).

However, I don’t think you need a servlet in the first place. If you do not want to access some of the container services, it would be better if you use the J2SE application to manage ServerSockets.

+5
source

Not quite sure what you want to achieve, but you can see client / server programming if you need it. In addition, you can implement your web application as usual, but change the default port to what suits you.

+2
source

All Articles