• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet is not a right choice to create a server process. Are you using GenericServlet or HTTPServlet?
 
reply
    Bookmark Topic Watch Topic
  • New Topic