Bonjour à tous,
voilà j'ai une appli. client/serveur qui fonctionne via TCP.
J'aimerai permettre l'échange de fichiers. Celui-ci marche mais uniquement pour des fichiers de certaines tailles (+/- 4ko...) après quoi, si je transfère, par exemple, un .rar de 10mo, j'obtiens 0 octets à l'arrivée...
J'ai fait pas mal de recherches, mais je ne comprends toujours pas pourquoi cette limite.
Voici mon code:
(le serveur envoie au client)
Code de l'envoi du fichier (coté serveur):
code de la réception du fichier (côté client):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 File toSend = new File(userPrefModel_.getPref()[1]+"\\"+askedFile); DataInputStream dataInput = null; try{ dataInput=new DataInputStream((new FileInputStream(toSend))); }catch(FileNotFoundException e){ e.printStackTrace(); } try{ byte i=dataInput.readByte(); DataOutputStream dataOutput = new DataOutputStream(clientOutput_); while(i!=-1){ dataOutput.writeByte(i); i=dataInput.readByte(); } }catch(IOException e){ e.printStackTrace(); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 DataOutputStream out = null; try{ out = new DataOutputStream(new FileOutputStream(f)); }catch(FileNotFoundException e){ e.printStackTrace(); } DataInputStream dataInput = new DataInputStream(inputStream_); try{ byte b = dataInput.readByte(); while(b!=-1){ out.write(b); b = dataInput.readByte(); } }catch(Exception e){ e.printStackTrace(); }
Une idée? :s
merci
Partager