HTTP Con. Error java.net.BindException: Address already in use: connect

Hi, i want to test a program that requests to a servlet continuously, then save the response to SQL (SQL Server 2000) database. But there is a problem.

After a while the program starts, it throws an exception and becomes throwing the same exception at each http request. I dont understand why?

I'm releasing the connection but it can not connect anymore...?

I had many change on the code, but it did not work.

The code for testing is :

import org.apache.commons.httpclient.HttpClient;

import org.apache.commons.httpclient.methods.PostMethod;

publicclass StressTest{

publicstaticvoid main(String[] args){

while(true){

PostMethod post =new PostMethod("http://localhost:8080/cepkisit/cepkisit");

HttpClient client =new HttpClient();

try{

client.executeMethod(post);

//System.out.println("post gerceklesti.");

}catch (Exception e){

e.printStackTrace();

break;

}finally{

post.releaseConnection();

}

}

}

}

The Exception :

java.net.BindException: Address already in use: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)

at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)

at java.net.Socket.connect(Socket.java:452)

at java.net.Socket.connect(Socket.java:402)

at java.net.Socket.<init>(Socket.java:309)

at java.net.Socket.<init>(Socket.java:124)

at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:86)

at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:652)

at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:628)

at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:497)

at alper.StressTest.main(StressTest.java:25)

[2942 byte] By [Lu-Siana] at [2007-10-2 2:19:53]
# 1
OK. The problem solved.HttpClient object (client) should be out of the loop. It uses a differenet port in each loop and it does not disconnect from that port. Because of this reason after a while, the ports of the machine are exhausted :) This is lucky ...
Lu-Siana at 2007-7-15 20:12:21 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

basic: Registered modality listener

liveconnect: Invoking JS method: document

liveconnect: Invoking JS method: URL

basic: Referencing classloader: sun.plugin.ClassLoaderInfo@1fae3c6, refcount=1

basic: Added progress listener: sun.plugin.util.GrayBoxPainter@e86da0

basic: Loading applet ...

basic: Initializing applet ...

basic: Starting applet ...

basic: httpCompression = true

network: Connecting https://secure.postplaza.nl/mailcenter/PrinterApplet.jar with proxy=HTTP @ /192.168.191.183:8080

network: Connecting socket://145.78.21.13:443 with proxy=DIRECT

basic: unique id: com_sun_deploy_AboutJava-1.5.0

basic: server port at: 1128

basic: getSingleInstanceFilename: C:\Documents and Settings\RDk\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_1128

basic: waiting connection

basic: httpCompression = true

network: Connecting https://secure.postplaza.nl/mailcenter/jaxp.jar with proxy=HTTP @ /192.168.191.183:8080

basic: Modality pushed

network: Connecting socket://localhost:1128 with proxy=DIRECT

basic: Modality popped

basic: recv: javaws.singleinstance.stop

basic: getSingleInstanceFilename: C:\Documents and Settings\RDk\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_1128

basic: getSingleInstanceFilename: C:\Documents and Settings\RDk\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_1128

basic: removed SingleInstanceFile: C:\Documents and Settings\RDk\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_1128

network: Connecting socket://145.78.21.13:443 with proxy=DIRECT

basic: httpCompression = true

network: Connecting https://secure.postplaza.nl/mailcenter/parser.jar with proxy=HTTP @ /192.168.191.183:8080

network: Connecting socket://145.78.21.13:443 with proxy=DIRECT

network: Connecting https://secure.postplaza.nl/mailcenter/nl/postplaza/applets/OrderPrinterApplet.class with proxy=HTTP @ /192.168.191.183:8080

network: Connecting socket://145.78.21.13:443 with proxy=DIRECT

network: Connecting https://secure.postplaza.nl/mailcenter/nl/postplaza/applets/OrderPrinterApplet/class.class with proxy=HTTP @ /192.168.191.183:8080

network: Connecting socket://145.78.21.13:443 with proxy=DIRECT

load: class nl.postplaza.applets.OrderPrinterApplet.class not found.

java.lang.ClassNotFoundException: nl.postplaza.applets.OrderPrinterApplet.class

at sun.applet.AppletClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.applet.AppletClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.applet.AppletClassLoader.loadCode(Unknown Source)

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: java.io.IOException: open HTTP connection failed.

at sun.applet.AppletClassLoader.getBytes(Unknown Source)

at sun.applet.AppletClassLoader.access$100(Unknown Source)

at sun.applet.AppletClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

... 10 more

basic: Exception: java.lang.ClassNotFoundException: nl.postplaza.applets.OrderPrinterApplet.class

How can i solve this problem?

Helpdeska at 2007-7-15 20:12:21 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...