[déplacé BAR -> JAVA] probleme envoie fichier via socket

thiernoirm Messages postés 12 Date d'inscription mercredi 1 juillet 2009 Statut Membre Dernière intervention 17 septembre 2009 - 10 juil. 2009 à 11:19
Kotomine Messages postés 112 Date d'inscription lundi 29 juin 2009 Statut Membre Dernière intervention 5 novembre 2009 - 10 juil. 2009 à 11:46
bonjour
j'essaye d'envoyer des fichiers via une socket par une methode,  mais j'ai toujours une erreur ( connection reset)
quelqu'un pourrai t il m'aider  SVP ?   MERCI

voici ma  methode :




public









void


envoie(){

String filePath =



"monFichier.txt"

;

ObjectInputStream in ;

ObjectOutputStream out;




try


{




if


(connexionServeur())


// methode se connecter serveur


{












if


(


sock

==



null


) System.



out


.println(


"Socket à null"

);




else


System.



out


.println(


"Client >> Socket ouvert"

);



/**Une






fois







la






socket






ouverte






on






peux







ecrire







ou







lire







dedans






*/





 


out =






new


ObjectOutputStream(


sock

.getOutputStream());in =




new


ObjectInputStream(


sock

.getInputStream());

FileInputStream FileInput =




new


FileInputStream(filePath);out.writeObject(FileInput);

out.flush();

StringBuffer buffer =




new


StringBuffer();




while


(



true


) {




int


charReceived = FileInput.read();




if


( charReceived == -1 ) {deconnexionSyrad();

System.




out


.println(


"connexion arretée"

);




break


;}

buffer.append(charReceived +



"\n"

);



reponseServeur

.setText(buffer.toString());}



//String fileContent = buffer.toString();


in.read();


}


}






catch


(IOException io){System.




out


.println(


"erreur envoie du Message : "

+io.getMessage());io.printStackTrace();

}

}

  ET     VOICI   L'ERREUR   QUE  J'AI

Client >> Socket ouvert

erreur envoie du Message : Connection reset






java.net.SocketException








: Connection reset

at java.net.SocketInputStream.read(Unknown Source)




at java.io.ObjectInputStream$PeekInputStream.read(Unknown Source)




at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)




at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)




at java.io.ObjectInputStream.readStreamHeader(Unknown Source)




at java.io.ObjectInputStream.(Unknown Source)




at VUE.InterfaceClient.envoie(








InterfaceClient.java:277






)

at VUE.InterfaceClient$ActionAdaptateur.actionPerformed(








InterfaceClient.java:429






)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)




at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)




at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)




at javax.swing.DefaultButtonModel.setPressed(Unknown Source)




at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)




at java.awt.Component.processMouseEvent(Unknown Source)




at javax.swing.JComponent.processMouseEvent(Unknown Source)




at java.awt.Component.processEvent(Unknown Source)




at java.awt.Container.processEvent(Unknown Source)




at java.awt.Component.dispatchEventImpl(Unknown Source)




at java.awt.Container.dispatchEventImpl(Unknown Source)




at java.awt.Component.dispatchEvent(Unknown Source)




at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)




at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)




at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)




at java.awt.Container.dispatchEventImpl(Unknown Source)




at java.awt.Window.dispatchEventImpl(Unknown Source)




at java.awt.Component.dispatchEvent(Unknown Source)




at java.awt.EventQueue.dispatchEvent(Unknown Source)




at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)




at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)




at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)




at java.awt.EventDispatchThread.pumpEvents(Unknown Source)




at java.awt.EventDispatchThread.pumpEvents(Unknown Source)




at java.awt.EventDispatchThread.run(Unknown Source)

4 réponses

Kotomine Messages postés 112 Date d'inscription lundi 29 juin 2009 Statut Membre Dernière intervention 5 novembre 2009
10 juil. 2009 à 11:26
Euh connection reset, c'est pas quand le serveur a fait un close() de son coté ?

Sinon, pourquoi tu as besoin  d'un ObjectXXXStream pour communiquer via le web ?
Un ObjectStream, c'est un truc de sérialisation. Ca va tenter de lire un objet sur son flux, et si c'est mal construit (c'est pas un objet qui circule) , ça ne va pas marcher.

; I'm just keeping the hopeless cross to increase the meaninglessness
0
krimog Messages postés 1860 Date d'inscription lundi 28 novembre 2005 Statut Membre Dernière intervention 14 février 2015 49
10 juil. 2009 à 11:37
Désolé, je ne suis pas très doué en langage "Le Bar".
Je ne vais pas pouvoir t'aider.

Krimog : while (!(succeed = try())) ;
- NON, "LE BAR" n'est PAS un langage de programmation ! -
0
thiernoirm Messages postés 12 Date d'inscription mercredi 1 juillet 2009 Statut Membre Dernière intervention 17 septembre 2009
10 juil. 2009 à 11:43
OK  pourrai tu   me montrer  une methode simple
juste pour envoyer un   fichier (fich.txt)   et recevoir  la rpeonse du serveur
stp
MERCI
0
Kotomine Messages postés 112 Date d'inscription lundi 29 juin 2009 Statut Membre Dernière intervention 5 novembre 2009
10 juil. 2009 à 11:46
Non. Mais google peut.

http://www.rgagnon.com/javadetails/java-0542.html

; I'm just keeping the hopeless cross to increase the meaninglessness
0
Rejoignez-nous