Software caused connection abort: socket write error

1. Software caused connection abort: socket write error

João Marcos Menezes
stremer

(usa Arch Linux)

Enviado em 25/04/2008 - 10:54h

Seguinte, tenho um programa em java (Applet) e ele efetua conexão com um servidor https, enviando dados e depois lendo os dados. As vezes ocorre este erro de "Software caused connection abort: socket write error", e pelo que andei pesquisando é um erro de rede (não consegui reproduzir o erro, ocorre em clientes). Foi recomendado trocar o inputstream e outputstream por BufferedInputStream e BufferedOutputStream mas mesmo assim em alguns locais dizem que o erro não continua ocorrendo e isto na verdade só "retarda" o problema. Será que tem algum jeito de contornar o problema? Segue abaixo o código:

byte[] buffer = null;
URLConnection urlConn = null;
OutputStream httpOut = null;
InputStream httpIn = null;

try {
urlConn = url.openConnection();
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
urlConn.setUseCaches(false);

Enumeration enu = requestProperty.keys(); //[2]
urlConn.setRequestProperty("Content-Type", "application/octet-stream");
urlConn.setRequestProperty("Content-Encoding", "binary");

while (enu.hasMoreElements()) { //[2]
Object key = enu.nextElement(); //[2]
urlConn.setRequestProperty(key.toString(),
requestProperty.get(key.toString()).toString());
}

// envia dados via http
httpOut = urlConn.getOutputStream();

if (bufferIn.length > 0) {
httpOut.write(bufferIn);
}

httpOut.close();

int bytes = 0;

int totalBytes = 0;

totalBytes = urlConn.getContentLength();

httpIn = urlConn.getInputStream();

if (totalBytes >= 0) {
buffer = new byte[totalBytes];

while (bytes < totalBytes) {
bytes += httpIn.read(buffer, bytes, totalBytes - bytes);
}
} else {
totalBytes = 0;
byte[] aux1;
byte[] aux2;
aux1 = new byte[TxRxFile.BLOCK_SIZE * 2];
aux2 = new byte[TxRxFile.BLOCK_SIZE * 2];

while (true) {
bytes = httpIn.read(aux1);
if (bytes < 0) {
break;
}
System.arraycopy(aux1, 0, aux2, totalBytes, bytes);
totalBytes = totalBytes + bytes;
}
buffer = new byte[totalBytes];
System.arraycopy (aux2, 0, buffer, 0, totalBytes);
}

httpIn.close();
} catch (Exception ex) {
throw new HttpTransferException(url, ex.getMessage());
}



  


2. ninguem?

João Marcos Menezes
stremer

(usa Arch Linux)

Enviado em 25/04/2008 - 15:59h

Pow esse problema ta me matando...






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts