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");

