IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Entrée/Sortie Java Discussion :

Exception Socket closed


Sujet :

Entrée/Sortie Java

  1. #1
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut Exception Socket closed
    Bonjour à tous. J'ai une appli qui se connecte sur différente socket. Il arrive qu'au moment de terminer la connexion et donc de fermer la socket je reçoivent l'exception suivante :

    09-28 15:19:33.421: WARN/System.err(931): java.net.SocketException: Socket closed
    09-28 15:19:33.421: WARN/System.err(931): at org.apache.harmony.luni.platform.OSNetworkSystem.write(Native Method)
    09-28 15:19:33.425: WARN/System.err(931): at dalvik.system.BlockGuard$WrappedNetworkSystem.write(BlockGuard.java:284)
    09-28 15:19:33.425: WARN/System.err(931): at org.apache.harmony.luni.net.PlainSocketImpl.write(PlainSocketImpl.java:472)
    09-28 15:19:33.425: WARN/System.err(931): at org.apache.harmony.luni.net.SocketOutputStream.write(SocketOutputStream.java:57)
    09-28 15:19:33.425: WARN/System.err(931): at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:190)
    09-28 15:19:33.425: WARN/System.err(931): at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:83)
    09-28 15:19:33.425: WARN/System.err(931): at java.io.FilterOutputStream.close(FilterOutputStream.java:60)
    09-28 15:19:33.425: WARN/System.err(931): at java.io.BufferedOutputStream.close(BufferedOutputStream.java:157)
    09-28 15:19:33.425: WARN/System.err(931): at my.app.net.NetworkClient.close(NetworkClient.java:186)
    09-28 15:19:33.425: WARN/System.err(931): at my.app.net.ThreadVideo.stopConnection(ThreadVideo.java:173)
    09-28 15:19:33.429: WARN/System.err(931): at my.app.net.ThreadVideo.finalize(ThreadVideo.java:413)
    09-28 15:19:33.429: WARN/System.err(931): at dalvik.system.NativeStart.run(Native Method)
    Le code correspondant est le suivant :

    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
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    public void close()
    {
    	if(this.socket != null && !this.socket.isClosed() && this.writer != null)
    	{
    		byte[] header 	= new byte[24];
    		header[0] 		= NetworkMessages.CLOSE_LINK;
    		header[10] 		= 24;
     
    		try {
    			this.writer.write(header);
    			this.writer.flush();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
     
    		if(!this.socket.isClosed()) 
    		{
    			try {
    				this.writer.close();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    			try {
    				this.reader.close();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    			try {
    				this.socket.close();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    		}
    	}
    }
    La partie qui semble lever l'exception est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    try {
    				this.writer.close();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    J'avoue ne pas comprendre , cette exception veux elle dire que la socket est déjà fermée au moment ou je fais mes close() ? Si c'est le cas ne devrais-je pas être bloqué par
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  2. #2
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Décembre 2010
    Messages
    734
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2010
    Messages : 734
    Points : 1 475
    Points
    1 475
    Par défaut
    Je crois que fermer l'un des flux ferme l'autre, et fermer les deux ferme la socket...
    getOutputStream

    public OutputStream getOutputStream()
    throws IOException

    Returns an output stream for this socket.

    If this socket has an associated channel then the resulting output stream delegates all of its operations to the channel. If the channel is in non-blocking mode then the output stream's write operations will throw an IllegalBlockingModeException.

    Closing the returned OutputStream will close the associated socket.

    Returns:
    an output stream for writing bytes to this socket.
    Throws:
    IOException - if an I/O error occurs when creating the output stream or if the socket is not connected.

Discussions similaires

  1. Exception ResultSet Closed
    Par vince85 dans le forum JDBC
    Réponses: 18
    Dernier message: 26/04/2011, 18h35
  2. Réponses: 3
    Dernier message: 05/02/2010, 14h09
  3. [JBoss-4.0.1] java.net.SocketException: Socket closed
    Par GyZmoO dans le forum Wildfly/JBoss
    Réponses: 7
    Dernier message: 27/11/2009, 08h39
  4. openldap : javax.naming.ServiceUnavailableException: localhost:389; socket closed
    Par identifiant_bidon dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 28/09/2009, 09h28
  5. Réponses: 6
    Dernier message: 04/12/2007, 20h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo