aspose file tools*
The moose likes Servlets and the fly likes 3 Servlets is a crowd! Why 3 instances of the same Servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "3 Servlets is a crowd! Why 3 instances of the same Servlet?" Watch "3 Servlets is a crowd! Why 3 instances of the same Servlet?" New topic
Author

3 Servlets is a crowd! Why 3 instances of the same Servlet?

John Lark
Ranch Hand

Joined: Feb 08, 2010
Posts: 72
Hey All,

I am trying to use a Servlet as a Socket Server which will respond to commands from my Socket Clients when they connect. My problem is that the servlet appears to be creating itself 3 times. The first time works fine, but the second and third time it flips out because the port they are trying to use has already been taken by first instance of the Server. The Server is not responding and I am assuming it is because this has munged it up. My web.XML settings are:

<servlet>
<servlet-name>SocketServer</servlet-name>
<servlet-class>com.Server.SocketServerr</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

I have tried both using an Init and a regular constructor. The same situation arises.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

That all makes sense to me (except the part where you decided you wanted to have a servlet act as a SocketServer). The first request creates a SocketServer which listens on port X, and presumably goes into a loop waiting for connections. The second and subsequent requests attempt to create a SocketServer which listens on port X, but of course they can't because something else is already listening on port X. You should not find this surprising.

I'm not sure why your server (you were referring to the SocketServer, not the servlet container, right?) is unresponsive. But that doesn't really matter because a servlet is an extremely poor choice for that task. I would suggest just running an ordinary server application which listens on port X and keep Java EE out of the picture entirely.
Pramod Kankure
Greenhorn

Joined: Oct 25, 2011
Posts: 6
Servlet is not a right choice to create a server process. Are you using GenericServlet or HTTPServlet?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 3 Servlets is a crowd! Why 3 instances of the same Servlet?