diff --git a/core/src/main/java/org/bitcoinj/net/BlockingClient.java b/core/src/main/java/org/bitcoinj/net/BlockingClient.java index a6762b269a22..fc0873e001fb 100644 --- a/core/src/main/java/org/bitcoinj/net/BlockingClient.java +++ b/core/src/main/java/org/bitcoinj/net/BlockingClient.java @@ -145,11 +145,14 @@ public void closeConnection() { @Override public synchronized void writeBytes(byte[] message) throws IOException { try { - OutputStream stream = socket.getOutputStream(); - stream.write(message); - stream.flush(); + if(!socket.isClosed()) { + OutputStream stream = socket.getOutputStream(); + stream.write(message); + stream.flush(); + } } catch (IOException e) { - log.error("Error writing message to connection, closing connection", e); + if(!(e instanceof SocketException && e.toString().equals("Socket is closed"))) + log.error("Error writing message to connection, closing connection", e); closeConnection(); throw e; }