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 :
Le code correspondant est le suivant :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)
La partie qui semble lever l'exception est :
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(); } } } }
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
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 try { this.writer.close(); } catch (IOException e) { e.printStackTrace(); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part this.socket.isClosed()
Partager