Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   JAVA (https://www.clubdelphi.com/foros/forumdisplay.php?f=16)
-   -   problema con flujos (https://www.clubdelphi.com/foros/showthread.php?t=46986)

danielfvalverde 15-08-2007 16:21:24

problema con flujos
 
hola!!
necesito ayuda...tengo armado un chat y le estoy agregando una parte donde el usuario puede subir archivos al servidor...
el tema es que el servidor no reconoce donde termina el archivo por lo que le mando un mensaje antes de enviar cada parte del buffer al servidor...pero no lo ve y pasa de largo en el while..(del server)


Cliente

salida = new PrintWriter(socket.getOutputStream(), true);


File file=new File (Archivo);
FileInputStream archivoaenviar = null;
try {
archivoaenviar = new FileInputStream(Archivo);
} catch (FileNotFoundException e1)
{
procesos.errorFatal(e1,"error al buscar el archivo");
}
byte[] buf = new byte[1024];
int len=0;
try {
while ((len = archivoaenviar.read(buf)) > 0)
{
salida.println("paquete2184");
System.out.println("se entro a donde se lee buffer" + buf);
salida.write(buf, 0, len);
}
} catch (IOException e1) {
e1.printStackTrace();
}
archivoaenviar.close();
System.out.println("seenviaarchivo");

SERVER

if (textoUsuario.equals("seenviaarchivo2184"))
{
salida.println("serecibepeticiondeupload2184");
System.out.println("se entro al metodo q recibe el archivo");
//CREO LA INSTANCIA PARA ESCRIBIR EL ARCHIVO EN DISCO
FileOutputStream out = null;
try {
out = new FileOutputStream(new java.io.File("C:\\llego.txt"));
System.out.println("se creo la salida a un archivo");
} catch (FileNotFoundException e) {
errorFatal(e,"error al generar el archivo de recepcion file not found");
}
byte[] buf = new byte[1024];
int len=0;
System.out.println("casi entra al try del while q lee el buffer");
try {
while ( (textoUsuario=entrada.readLine()) == "paquete2184" )
System.out.println("entro al while del paquete");
while((len = entrada.read(buf)) > 0)
System.out.println("se entro a donde se lee buffer" + buf);
out.write(buf, 0, len);
break;
}
}
} catch (IOException e) {
errorFatal(e,"error al leer el buffer del archivo recibido");
}
try {

out.close();
} catch (IOException e) {
errorFatal(e,"error al cerrar flujos o al crearlo");
}
out.close();


La franja horaria es GMT +2. Ahora son las 00:02:00.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi