aspose file tools*
The moose likes Tomcat and the fly likes listen on multiple ports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "listen on multiple ports" Watch "listen on multiple ports" New topic
Author

listen on multiple ports

Paul Erion
Greenhorn

Joined: Jul 11, 2003
Posts: 5
Is it possible for a single instance of Tomcat to listen on multiple ports?

Thanks,

aul
Carl Sampson
Greenhorn

Joined: Apr 09, 2003
Posts: 22
Well, yes and no. It can be listening on one port for HTTP and another for HTTPS, for example. But I don't think it can listen using the HTTP transport on multiple protocols, for example.
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Sampson is right... We can specify multiple ports for different protocols...

Paul Erion, if you are trying to assign multiple port for a single protocol, how can Tomcat know which protocol to use, when it get a certain request with different port numbers.... Tomcat will use to a suitable protocol, according to the port number it gets...

Hope it helps..


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by Paul Erion:
Is it possible for a single instance of Tomcat to listen on multiple ports?

Thanks,

aul


Sure, you can do it.

Tomcat is support several protocol such as HTTP(80/8080) default, HTTPS.

How to HTTPS on Tomcat ::

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/ssl-howto.html

http://java.sun.com/webservices/docs/1.0/tutorial/doc/WebAppSecurity6.html


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Budi Kurniawan
author
Greenhorn

Joined: Sep 15, 2004
Posts: 12
Originally posted by Paul Erion:
Is it possible for a single instance of Tomcat to listen on multiple ports?

Thanks,

aul


I think what Paul wanted to know was whether a protocol (HTTP or HTTPS) can listen on multiple ports. The answer is yes. In the server.xml file, find the following (in Tomcat 5):

<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />

As you can see, by default Tomcat listens on port 8080. If, for example, you want Tomcat to listen on another port, say 8081, just add this below the previous Connector element:

<Connector port="8081"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />


The reason for this is this.
The Connector element represents a connector. Upon startup, Tomcat will parse the server.xml file and create objects based on the content of the file. A Connector element will cause Tomcat to create a Connector object. Another Connector element will give you another instance of Connector. With the above configuration, you have 2 connectors listening on port 8080 and 8081 respectively. You only have one container though. The connectors create a request and response object for each incoming HTTP request and pass it to the container.

You can read Chapter 3 of our How Tomcat Works book that discusses connector. This chapter is freely available from www.brainysoftware.com


Author of <a href="http://www.amazon.com/exec/obidos/ASIN/097521280X/ref=jranch-20" target="_blank" rel="nofollow">How Tomcat Works</a>
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Thanks for the great explanation, Budi... I got them clearly now also...

Even though we can have two connectors listening to different ports, there is only one container which handle the requests from them...
Carl Sampson
Greenhorn

Joined: Apr 09, 2003
Posts: 22
What's the advantage to having more than one connector if they both process connections for the same container?
Paul Erion
Greenhorn

Joined: Jul 11, 2003
Posts: 5
Originally posted by Budi Kurniawan:


I think what Paul wanted to know was whether a protocol (HTTP or HTTPS) can listen on multiple ports. The answer is yes.
Thanks for the response! And in figuring out what I trying to ask -- I didn't mean to be difficult ... it just always seems to work out that way.

Paul

p.s., I apologize for my signature ... I typically precede my first name with a colon (it's a Lisp thing) and didn't realize it would end up being interpreted as a emoticon.
[ September 16, 2004: Message edited by: Paul Erion ]
Simão Fontes
Greenhorn

Joined: Nov 09, 2009
Posts: 3
I have a tomcat 5.5.25 configured with 4 connectors and when it was only one the response time was about 1.30 sec, now it responds in 16 sec.
Does any one know why this migth be?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16308
    
  22

Tomcat is actually a set of components wired together. While mostly it's employed in the out-of-the-box wiring configuration, you can add elements to server.xml to provide multiple Host, Engine, Connector and other such items in a custom architecture.


Customer surveys are for companies who didn't pay proper attention to begin with.
Simão Fontes
Greenhorn

Joined: Nov 09, 2009
Posts: 3
My problem is the performance lost.

My server.xml is configured like this:

I had to do this because the applications communicate with them selfs.
For example:
app1 --> app2 --> app3
app2 --> app1 --> app3

When I use all threads for one of the applications, they enter in deadlock (they always need to wait for another application to end).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16308
    
  22

You don't need a separate set of ports for each webapp just because they're talking to each other. One port is sufficient. Tomcat will route the requests based on their URL context.

You can get race conditions, "deadly embrace" and resource contention issues without any web architecture at all, however, so I recommend drawing a detailed map of what calls what when, how the components interact, and maybe slap some performance-monitoring on the server in case both apps are trying to make large database operations at the same time.
Simão Fontes
Greenhorn

Joined: Nov 09, 2009
Posts: 3
Thanks for the answer Tim.

I have 2 applications, wayback and nutchwax, they belong to a search server.

*Nutchwax -> Index -> User
*Wayback -> *Nutchwax -> Index -> User
*Wayback -> *Nutchwax -> Index -> *ArcProxy -> *Browser -> User
* means that this is a application of tomcat

The fact is when I configure Tomcat to have 100 MaxThreads and then I make 100 simultaneous requests to Wayback the threads stop responding, keeps waiting for the arcproxy application, this application doesn't have any free thread to use.

Thanks in advance for the help.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: listen on multiple ports