You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Zhidong Yu <zh...@ipedo.com> on 2002/06/18 03:50:33 UTC

Difference beteen Tomcat 3.3 and 4.0 in handling TCP connection?

I wrote a simple Http client to connect with tomcat 3.3 and tomcat 4.0.
The client and server run at two different Windows 2000 machine. After
the client run to end, I use "netstat -nap TCP" to print out all live
connections, and the result is different between Tomcat 3.3 and 4.0. 

With Tomcat 3.3, no live connection exists at client side. But with
Tomcat 4.0, there are many live connections exists with status of
TIME_WAIT of FIN_WAIT_2. It seems there is some different behavior with
TC3.3 and 4.0.

Do any of you know why?

Following is my client code.
=========================================================
public class Client implements Runnable{
	static String _urlStr = null;
	static int _loop = 0;

    public Client() {
    }
	
	public void run(){
		System.out.println("Thread \"" +
Thread.currentThread().getName()
			+"\" started.");

		for (int i=0; i<_loop; i++) {			
        HttpURLConnection m_connection = null;
        URL url = null;

        try{
            url = new URL(_urlStr);
        }catch (Exception e){
            e.printStackTrace();
            return;
        }

        try {
			m_connection = (HttpURLConnection)
url.openConnection();
			m_connection.setDoInput(true);
			m_connection.setDoOutput(true);
			// Disable caching
			m_connection.setUseCaches(false);
			m_connection.setRequestMethod("POST");
	
			m_connection.setRequestProperty("Content-Type",
"text/plain");
			byte[] data =
Thread.currentThread().getName().getBytes();
	
m_connection.setRequestProperty("Content-Length", ""+data.length);
			OutputStream output =
m_connection.getOutputStream();
			output.write(data);
			output.flush();
			output.close();
	
			// return servlet response as a DataInputStream
	        DataInputStream res = new
DataInputStream(m_connection.getInputStream());
			byte[] baRes = new
byte[m_connection.getContentLength()];
	        res.readFully(baRes);
	        System.out.println("Response is \"" + new String(baRes)
+"\"");
	
			m_connection.disconnect();

        }catch(Exception e){
            System.out.println(e.toString());
        }
		}

	}

    public static void main(String args[]){
		if (args.length != 3){
			System.out.println("Client <url> <thread_number>
<loop>");
			return;
		}
		
		_urlStr = args[0];
		int threads = Integer.parseInt(args[1]);
		_loop = Integer.parseInt(args[2]);
		
		for (int i=0; i<threads; i++){
			new Thread(new Client()).start();
		}
    }

}



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>