Big headache with URL connection

Hi, guys.

i wrote an applet that measures response time of some html components, like gifs! The applet should return this wasted time by the actionperform method be executed, since this method opens a url connection with a html component. So it might return the final response time, but the result is always 0 !!! Please, could anybody help me?

Regards Euclides.

public void actionPerformed(java.awt.event.ActionEvent actionEvent) {

long valor;

Integer valornovo;

String valor1,tam1,tarefa1;

JTextField aux;

tam1 = (String)ivjJComboBox1.getSelectedItem();

tarefa1 = (String)ivjJComboBox2.getSelectedItem();

valor = mandabala(tam1,tarefa1);

valor1 = Long.toString(valor);

//delayField = new JTextField(Long.toString(delay), 6);

//valor1 = Long.toString(valor);

ivjJTextField1.setEnabled( true );

ivjJTextField1.setText(valor1);

validate();

public long mandabala(String param, String param1) {

long time;

long time1;

BufferedInputStream in;

java.net.HttpURLConnection conn;

java.net.URL url;

url = null;

if (param == "100")

{

byte[] buffer = new byte[99990000];

try {

url = new java.net.URL("http://10.0.135.15/teste.gif");

// url = constructURL("http://10.0.135.15/performance/teste.gif");

conn = (HttpURLConnection)url.openConnection();

time = System.currentTimeMillis();

//conn("http://www.dataprev.gov.br/performance/teste.gif");

//conn("http://10.0.135.15/performance/teste.gif");

conn.connect();

time1 = System.currentTimeMillis();

in = new BufferedInputStream(conn.getInputStream());

int x = 0;

while((x = in.read(buffer))!=-1)

timedif = System.currentTimeMillis() - time;

in.close();

}

catch(Exception e) {

System.out.println("Erro de conexao");

[1942 byte] By [euclidesjr] at [2007-9-26 4:47:40]
# 1

I read it really quickly, so I apologize if you've checked this already...

Your while loop is not executing the statement you are using to compute the timediff variable. The while loop in.read() method returns with a value of say '63000' when the .gif file is read. Since 63000!=-1 the loop exits immediately without executing the statement (System.currentTime()) in the middle.

To correct this, you should do the following.

long timediff=0;

long starttime=System.currentTimeInMillis();

int character=0;

while( (character=in.read()) != -1 );

timediff = System.currentTimeINMillis() - starttime;

//return timediff;

CWalker807 at 2007-6-29 18:37:32 > top of Java-index,Core,Core APIs...