Foro de elhacker.net

Programación => Programación General => Mensaje iniciado por: momo1234 en 14 Mayo 2012, 22:36 pm



Título: probleme de recivir datos completos con servidor socket
Publicado por: momo1234 en 14 Mayo 2012, 22:36 pm
hola todos tengo un problema cuando envio un fichero de 76k recivo solo 70k aqui esta mi codigo muchas gracias .

Servidor
Código:
 public void run()
    {
        try
        {
            InputStream in = socket.getInputStream();
            DataInputStream dis = new DataInputStream(socket.getInputStream());
            String file = dis.readUTF();
            String file1 = dis.readUTF();
            String file2 = dis.readUTF();
            int i = dis.readInt();
            creerdossier(file,file1,file2);
            if(i == 1)
            {
         
            }
            if(file != null)
            {
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("C:\\dossier\\"+file1+"\\"+file2+"\\"+ file));
                byte buf[] = new byte[1024];
                int len;
                while((len = in.read(buf)) != -1 )
                {
                    bos.write(buf, 0, len);
                }
            }
        }
        catch(IOException e)

Cliente

Código:
      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(direccionArchivo));
            BufferedOutputStream bos = new BufferedOutputStream(via.getOutputStream());

            //Enviamos el nombre del archivo
            DataOutputStream dos = new DataOutputStream(via.getOutputStream());
            dos.writeUTF(archivo.getName());
            dos.writeUTF(s);
            dos.writeUTF(s1);
             dos.writeInt(1);
      //  dos.writeInt(2);
           

            byteArray = new byte[1024];
            while ((in = bis.read(byteArray)) != -1)
            {
                bos.write(byteArray,0,in);
            }
via.close();       
bis.close();
bos.close();

gracias a todos.