Tuesday, October 05, 2010

ConnectException when connecting to Tomcat

If you are experiencing following exception when you try to connect to tomcat either using Java socket, TCP Monitor or any other means, then try the following procedure:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)

Go to conf directory in the Tomcat installation directory, and then edit the server.xml as follows:

<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"

By default Tomcat does not come with the address attribute, once you set that to localhost or any address you want, then you will be able to solve the above exception.